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

learn more… | top users | synonyms

10
votes
6answers
9k views

How do I recursively grep through compressed archives?

I'm trying to find out what modules use Test::Version in cpan. So I've used minicpan to mirror it. My problem is that I need to iterate through the archives that are downloaded, and grep the files ...
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 ...
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 ...
0
votes
2answers
1k views

Curl and grep html text

Is there a way to grep html text from a curl request and output grab the value that is between two html tags? More specifically the input value of a form?
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 ...
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 ...
24
votes
3answers
31k views

How to run grep with multiple AND patterns?

I would like to get the multi pattern match with implicit AND between patterns, i.e. equivalent to running several greps in a sequence: grep pattern1 | grep pattern2 | ... So how to convert it to ...
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
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 ...
6
votes
1answer
644 views

grepping foo and bar [duplicate]

I am looking for a command options for grep to find files with the occurences of foo and bar. Grepping with grep -r -e foo -e bar . shows files which have only foo or only bar and files which ...
5
votes
3answers
2k views

How to search files where two different words exist?

I'm looking for a way to search files where two word instances exist in the same file. I've been using the following to perform my searches up to this point: find . -exec grep -l "FIND ME" {} \; ...
8
votes
4answers
31k views

How to add a carriage return before every newline?

I have a file that only uses \n for new lines, but I need it to have \r\n for each new line. How can I do this? For example, I solved it in Vim using :%s/\n/\r\n/g, but I would like to use a script ...
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
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 ...
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 ...
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 ...
3
votes
4answers
3k views

Find files containing one string but not the other

I am in a folder with lots of .txt files, I would like to find all the files which contain stringA but don't contain stringB (they are not necessarily in the same line). Does anyone know how to do ...
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 ...
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 ...
0
votes
4answers
642 views

Unix grep confusion

I am doing an assignment for school and using putty to complete the assignment. The format of the assignment does not allow for much variation and thus only one answer is sufficient enough to allow me ...
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 ...
-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 " ...
6
votes
1answer
2k views

How can I keep color codes with grep input?

If I use two consecutive grep commands, e.g.: echo "foo bar" | grep foo | grep bar Then the first pattern ("foo") is not highlighted. In fact, it seems that grep removes color codes from its input. ...
7
votes
3answers
10k views

Grep in couple thousands files

I have directory with cca 26 000 files and I need to grep in all these files. Problem is, that I need it as fast as possible, so it's not ideal to make script where grep will take name of one file ...
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 ...
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 ...
-1
votes
1answer
41 views
-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 ...
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 ...
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 ...
3
votes
2answers
3k views

Concatenate specific files into one single file

In a folder containing X files, I need to concatenate Y files (where X > Y) together into a single text file. I have the filenames (of Y files) that I need to concatenate. Can anyone please help me ...
2
votes
2answers
41 views

How to find/grep what is between string1 and string2?

I am trying to extract a value from a long string that may change over time. So for example the string could look something like this ....../filename-1.9.0.3.tar.gz"<.... And what I want to ...
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. ...
3
votes
1answer
87 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
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 ...
1
vote
1answer
34 views

List lines that consist of a single non-vowel character

I need help with listing lines that consist of a single non-vowel character. I got this: ls | grep -nv '[aeiouy]' file But this doesn't give me a single character. How do I get just a single ...
1
vote
2answers
74 views

List files that don't have certain letters in the first two character

I need help with listing filenames that are at least two characters long and don't have the following letters in the first two characters. The letters are abcfghxyz So far I have: ls | grep -v ...
12
votes
5answers
44k views

How to find the path of a file based on its name?

I am trying to find settings.xml file in my Ubuntu machine. I have no clue where it is, and which directory it is in. I tried using this - ls -R | grep settings.xml But it doesn't show me the ...
3
votes
3answers
269 views

non-greedy grep

I want to grep a link from an external file example.txt. example.txt containins: (https://example.com/pathto/music.mp3)music.mp3 the code: egrep -o -m1 '(https)[^'\"]+.mp3' example.txt output: ...
120
votes
12answers
44k views

How can I prevent 'grep' from showing up in ps results?

When I search for some process that doesn't exist, e.g. $ ps aux | grep fnord wayne 15745 0.0 0.0 13580 928 pts/6 S+ 03:58 0:00 grep fnord Obviously I ...
1
vote
6answers
11k views

compare two files get identical list

file1.txt (50 lines) TERYUFV00000010753 TERYUFV00000009526 file2.txt (500 lines) TERYUFV00000009526 refids_739_known_8/10_target TERYUFV00000018907 refids_12023_known_21/22_target ...
1
vote
1answer
201 views

Find and delete lines containing multiple patterns in a file

I have a list of strings and want to find and delete lines containing these strings in a file. A short example of the list of strings is listed as below. File S 1Mo 32,33 2Mo 7,26 2Mo 7,27 2Mo 7,28 ...
4
votes
3answers
185 views

How to search efficiently for a list of strings in a big code directory

I have a list of strings, for every of those strings, I want to check if it occurs in a big source code directory. I came to a GNU grep solution that gives me what I want: for key in $(cat ...