grep is a command-line tool for searching text patterns in files

learn more… | top users | synonyms

2
votes
2answers
79 views

Sorting one file line by line based on another file

I'm trying to sort the rows of a text file based on an 'index' in another file, such that the text file is arranged, row by row, in the same order as the index file. The following code achieves what ...
-3
votes
1answer
25 views

How do i create a sed script to prompt the user to replace a number in a file? [duplicate]

I'm new in Unix, and I'm learning about sed command. I need to write a very small script for searching a number in a file and replacing it. I tried doing grep, and than deleting the specific phone ...
0
votes
2answers
43 views

return first instance of characters from a list

Lets say I have the output of this command saved to a file. cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50 I would like to compare only the first n ...
-1
votes
3answers
33 views

How to filter log file for string inside single quotes?

I have a log file, which outputs information this way: 2016-01-01: foo bar fnord 2016-01-01: this is static 'this is of interest' some blob bar 2016-01-01: this is static 'this is of interest' some ...
0
votes
2answers
41 views

Piping sed/grep output does not work

If I run the commands bellow, only out1 has output, the out2 and out3 are empty. # this is just to generate a self-signed certificate openssl genrsa -out /tmp/ssl.key 2048 openssl req -sha256 -new ...
0
votes
3answers
43 views

How can i extract data from this line?

xyz /mnp/opq/p/1926081/sp/192608100/serveFlavor/entryId/0_ffx7sljc/v/2/flavorId/0_,n6h1xlhl,ea3anltg,jfs8boo9,w2v1vsk2,ze8e1q2s,to8w2p18,/forceproxy/true/name/new in this line this part ...
3
votes
3answers
94 views

Is it possible to use grep lookaroud multiple times?

<table name="content_analyzer" another-key="id9"> <type="global" /> </table> <table name="content_analyzer2" another-key="id12"> <type="global" /> </table> ...
1
vote
1answer
40 views

How do I use multiple options for grep (on live output)?

For example, when I do this sudo tcpdump | grep -E '.dev:8888|ads' | grep -v 'adsl' ALL output is suppressed for some reason, nothing is shown if I access ads.google.com for example, it does show ...
3
votes
1answer
49 views

Filtering the colored output of grep

I'm on OSX, but I suspect this doesn't make a big difference for this question. In my .bash_profile, I aliased grep to get color outputs by default: alias grep='grep --color=always' I commonly run ...
3
votes
3answers
120 views

Add mtime to grep -c output and sort the output by mtime

I have a directory full of logs named in the following style: info.log00001 info.log00002 info.log00003 ... info.log09999 info.log My current output (using grep -c) I need to analyze the ...
1
vote
2answers
57 views

Tar files starting with the same pattern

I have some log files named : 2016-02-10_03-52.log 2016-02-10_04-43.log 2016-02-10_02-13.log ... 2016-03-15_07-03.log 2016-03-15_09-08.log Basically the pattern is : YYYY-MM-DD_.log I would ...
0
votes
1answer
53 views

Compare 1st column of the 1st file and 2nd column of the 2nd file and matching

File1: Excel file (.xls) UN ID St M1 M2 SE DOF PV PA FC 17127159 0 -5.9 297.3 765.7 0.22 4 0.003 0.00389231 2.57536 17127163 2 ...
-1
votes
2answers
21 views

count lines in with 2 words

I have a text file with many lines like - The quick brown fox jumps over the lazy dog The quick brown fox did not jumps over the lazy dog The quick brown fox may jumps over the lazy dog The quick ...
2
votes
1answer
77 views

GNU parallel excessively slow

I need to run grep on a couple of million files. Therefore I tried to speed it up, following the two approaches mentioned here: xargs -P -n and GNU parallel. I tried this on a subset of my files (9026 ...
6
votes
1answer
299 views

grep --exclude does not exclude my file

I am searching a dir for a particular string (to see all instances of where the string is present and in which files). However, I want to exclude one particular file from being searched. Here's what ...
0
votes
2answers
79 views

Curl and Grep to Parsing Content

I need to parse the output of a curl command: curl --user test:test http://192.168.1.1/security/pkm.html | egrep '@company|config.pkm.password' This returns: <input type="text" ...
0
votes
0answers
16 views

Different regex engines and syntax in unix tools like grep, find, vim, sed, aptitude etc [duplicate]

I would like to learn and use regex more. I made couple tutorials and trying use regex in everyday tasks. But I've found thing that demotivates me and slowing learning process - different ...
0
votes
4answers
26 views

Extracting a text backwards from a selected character

I am quite newbie with scripting. I have a file with following lines: handleNewConnection:: User langfordm@system.com has 2 active nodes handleNewConnection:: User bas102@system.com has 2 active ...
0
votes
1answer
46 views

Awk and Grep to get data from CLI

I want to get output as below: Number Name Value ************************************* 889900 Staff 256000 990088 Staff 1048576 And my input would be as below: ...
2
votes
1answer
28 views

Will zgrep recursively search zips embedded within zips?

I am using the zutils version of zgrep v0.9 (not the gzip wrapper script) and to recursively grep zip files starting from the current folder I simply use: zgrep -r "MY_STRING" . This works fine. ...
0
votes
3answers
45 views

How to test which strings from File A are not present in File B, without displaying anything that is present in File B and not in File A?

I have a text file, say sitelist1.txt (File A), that has some URLs like below: http://www.facebook.com http://www.twitter.com http://myspace.com/profile http://orkut.com/archived I have another ...
0
votes
2answers
53 views

Problem with grep -o

I have a text file as shown below. 192.168.10.1 192.168.45.45 192.168.255.255 192.168.0.5 Random text comes here 8.8.8.8 224.23.25.12 225.1.2.3 226.0.0.0 ...
1
vote
1answer
32 views

Examine a bunch of huge files

I have a folder with big files (few GB each). I would like to search aPATTERNthrough these files. I can do this with grep or ack: $ grep -n 'PATTERN' /path/to/files/*.log Now, I have a list with ...
1
vote
0answers
34 views

Find list items in other file [duplicate]

I have one file with hundreds of unique IP addresses (each on a separate line) from which a bot tries to login to one of our services. I would like to see which of these addresses appear in another ...
1
vote
2answers
24 views

How extract under linux some capturing groups using command line in a php/preg fashion?

Given in linux environment exists lot of packages for manipulating strings (grep, awk, sed, ...), I would like a software to extract a capturing group in a php/preg like syntax. Maybe the most close ...
0
votes
3answers
72 views

Using rpm/grep to check whether multiple services are installed - as one liner?

The following code is used to check whether a service (read from variable, can be empty or up to X services named) is installed or not and take appropriate action. ... if ! rpm -qa | grep -qw ...
0
votes
2answers
62 views

How to get only certain fields from a given file?

I have list of employees in following format Name: Phone No: Email: Name: Address: Phone No: Email: Name: Country: Address: Phone No: Email: Name: Address: Name : Email: Address: All I want ...
1
vote
2answers
80 views

Find files containing a set of words

I'm using grep to find files within a directory, containing a set of words. But grep search lines containing these words, what I want is grep to show me the files or file containing all those words ...
0
votes
1answer
31 views

Does find Command Do Match For Regexp Because Of Implementation?

In this case discussed: find (GNU findutils) 4.5.11 grep (GNU grep) 2.20 Let's say I have a directory that contains a bunch of files. I want to find the files named jtobdops02.key and ...
0
votes
1answer
36 views

Monitoring Server Connections - Netstat formatting issue

I have had a few issues with a server recently. So i just wanted to leave a window showing the unique and IP's of connected devices. I have been using: watch -n 5 "netstat -tn 2>/dev/null | grep ...
3
votes
1answer
40 views

Get contents of a file from first instance to last instance of some arbitrary string

How can I view in less from the first instance of some arbitrary string "foo" to the last instance? This arbitrary string will be on most every line of the log. I don't want to do grep "foo" bar.log ...
0
votes
1answer
46 views

How to grep response to figure out how many calls got timed out?

I have a curl command which is calling one of our service so if my service timesout, it returns JSON response like below: [{"results":{"response":null},"error":{"errorCode":1001,"message":"Service ...
0
votes
2answers
43 views

Bash Script with Multiple Lines and Grep

I have output from a specific command that can provide the number of times an application has been marked as 'used' on an OS X system. The command is mdls. The output looks similar to the following ...
0
votes
2answers
50 views

insert complex line before or after complex line

i have file with complex text print("ERROR: passwords don't match") password = hash_func(password.encode("UTF-8")).hexdigest() i need to insert this text between them with ...
-1
votes
1answer
35 views

Searching for most recent file (Display Unique)

If i have a Folder structure with 10 Sub dirs Each sub folder has the possibility to hold a version of a file (Older or newer) "Poor folder structure." I was looking to use Find to locate all files ...
0
votes
0answers
35 views

How to use gnu parallel to improve grep within while a loop [duplicate]

I have this loop as you see it makes two greps. The files are huge and grep are very slow.How I can implement gnu parallel in this loop? while read lemma stem POS do date "+%T ${lemma}..." grep -E " ...
0
votes
3answers
62 views

Grep in many directories, but only look in each dir's specific subdirectory, not all sub dirs

My case: dir1 subdir1 FooFile subdir2 dir2 subdir1 FooFile subdir2 So, if I cd dir1, I can easily do something like find . | xargs grep "Foo" in order to list the names of ...
3
votes
1answer
56 views

Remove files with match only from some subdirectories

I have a directory with several subdirectories; in each of these, I have some files. I want to perform a grep only for some subdirectories to find those files that match the query and remove them; ...
1
vote
2answers
33 views

Sed from line 6 on from all txt files and being able to output all the results in a single file

I need to sed from all *.txt files from line 6 until the end All the results should be in a new single file with the name of each file preceding the results Example: Having different txt files the ...
0
votes
2answers
41 views

using awk to unzip files in directory

I have some zip files in directory when I need to unzip each in specific dir I used ls | awk '{ print "unzip " $1 " -d " $1} ' unzip p21286665_121020_Linux-x86-64.zip -d ...
45
votes
2answers
4k views

Why is egrep [wW][oO][rR][dD] faster than grep -i word?

I've been using grep -i more often and I found out that it is slower than its egrep equivalent, where I match against the upper or lower case of each letter: $ time grep -iq "thats" testfile real ...
-1
votes
1answer
41 views

how can i extract the second and third word of a line{that starts with 9} from a file where words are seperate with |? [closed]

case "$3" in -id) echo "Lines matches with the pattern $4 :" #grep -oP $4 $2 ;; esac
-1
votes
1answer
25 views

Remove pattern from a line in file with Grep/sed/awk combo, pattern is another column

I have two columns (or could separate as two files) in a huge file and i need to remove the duplicate city name in the state/area column. los angeles los angeles ca, usa, west new york ...
3
votes
3answers
36 views

Strings - Extract File Version Recursive

I have been using strings to extract and compare file versions between directories. I don't seem to be able to do this recursively. The method I have been using per file is: strings -e l ...
5
votes
3answers
49 views

How can I get the seprate results for each pattern from multiple grep

I would like to search 14 different patterns within 100 files. At the moment what I tried cat s_3_2_*_qseq.txt | grep -c 'pattern1\|pattern2\|pattern3\|pattern4\|pattern5\|...pattern14' This ...
1
vote
2answers
50 views

Using Grep Command Without Specifying a Certain Directory [closed]

Can you use the grep command without specifying a directory path afterwards? Example: $ sudo grep "filename" / I have also tried this: sudo find / -type f grep -l "filename" Still no luck. ...
1
vote
4answers
60 views

cat results of grep

I am trying to concatenate the results of my grep search. my grep search finds about 4 files on my system and outputs them in a new line for each file. I thought by passing this information to tr '\n' ...
0
votes
2answers
68 views

Using Both Grep and Cut

I want to grep the output of tcpdump and cut some part of it but the command below is not working. tcpdump ... | grep -i --line-buffered "..." | cut -d'&' -f1,2 Do you know what is the problem? ...
0
votes
3answers
54 views

highlighting parameters in with grep

I'm in need of some assistance with using the highlight feature in bash. My goal is to grep three parameters and then highlight them with three different colors. I've been messing around with this ...
3
votes
1answer
70 views

How to optimize 'grep'-and-save?

I want to know on which node my calculations were running on our cluster in case the node crashes and I get no files back to know on which node I have to search. For that case I wrote a little script ...