Questions tagged [grep]

grep is a command-line utility that is used for searching text.

grep is a command-line utility that is used for searching text from standard input or a file for specific expressions, returning the lines where matches occur.

A common use for grep is to locate and print out certain lines from log files or program output.

See this Ubuntu Documentation page for more information on how to use grep.

747 questions
507
votes
12 answers

How to use "grep" command to find text including subdirectories

I want to find all files which contain a specific string of text. The grep command works, but I don't know how to use it for every directory (I can only do it for my current directory). I tried reading man grep, but it didn't yield any help.
Smile.Hunter
  • 8,705
191
votes
4 answers

How to grep for tabs without using literal tabs and why does \t not work?

When I search for tabs in a file with (e)grep I use the litteral tab (^v + ). I can not utilize \t as a replacement for tabs in regular expressions. With e.g. sed this expression works very well. So is there any possibility to use a…
Lasall
  • 3,733
155
votes
4 answers

How can I recursively search for directory names with a particular string where the string is only part of the directory name

How can I recursively search for directory names with a particular string where the string is only part of the directory name? For example: the directory name is "8.0.3-99966_en", but I want to recursively search for directories with the string…
Bob Perez
  • 1,651
110
votes
5 answers

How do I fetch only numbers in grep?

I have file like this : other lines . . . blah blah blah (:34) I wish to find the occurrence of numbers in the above file. I came up with: grep [0-9] filename But that is printing the whole: blah blah blah (:34) Rather I want only 34. Is…
Ant's
  • 3,930
73
votes
1 answer

How can I watch the output that was filtered with grep?

I want to watch the changes of the output gsettings list-recursively|grep text-scal which is org.gnome.desktop.interface text-scaling-factor 1.0 com.canonical.Unity.Interface text-scale-factor 1.0 but if I try to watch it with watch gsettings…
rubo77
  • 34,024
  • 52
  • 172
  • 299
68
votes
7 answers

Grep searching two words in a line

I've been trying to find a way to filter a line that has the word "lemon" and "rice" in it. I know how to find "lemon" or "rice" but not the two of them. They don't need to be next to the other, just one the same line of text.
Sebastian
  • 785
68
votes
6 answers

grep -- list file name where match is found

I have a bunch of .html files in a directory. I want to look through each file and match a pattern (MD5). All of that is easy enough. The problem is I need to know what file the match was found in. cat *.html | grep…
BeMy Friend
  • 1,173
61
votes
6 answers

How to use grep on all files non-recursively in a directory?

I want to search for a string of text in all files in a directory (and not its subdirectories; I know the -r option does that, but that is not what I want). Running grep "string" /path/to/dir is supposed to be able to do this, I've read, but it…
John Red
  • 909
61
votes
4 answers

How to grep 2 or 3 lines, one containing the text I want, and the others just below it?

This is a snapshot of error log: 06:16:29,933 ERROR EmailRMManager$:45 - Exception In get Message com.rabbitmq.client.AlreadyClosedException: clean connection shutdown; reason: Attempt to use closed channel at…
theTuxRacer
  • 16,533
60
votes
5 answers

Grep, ignore warnings

I am trying to find the installation directory of a particular package. I have a certain keyword using which I am trying to find a particular file. During grep, I only want to include cpp or h file type. I do not want the grep to show warnings like…
52
votes
4 answers

How to grep for groups of n digits, but no more than n?

I'm learning Linux, and I have a challenge that I seem to fail to solve on my own. Here it is: grep a line from a file which contains 4 numbers in a row but not more than 4. I'm not sure how to approach this. I can search for specific numbers but…
Buddha
  • 539
51
votes
3 answers

tail a log file but show only specific lines

I'm tailing a log file with -f flag. Then I'm piping this to grep, to find only lines that contain "X". That's working perfectly fine. Now I want to pipe this again into another grep, that will remove all the lines containing "Y". When I add the…
Ori Horev
  • 513
  • 1
  • 4
  • 5
51
votes
2 answers

grep "+" operator does not work

This ls -l /var/log | awk '{print $9}' | grep "^[a-z]*\.log." outputs…
Marko
  • 792
  • 2
  • 6
  • 8
50
votes
1 answer

omit filenames in grep

I am greping a string from multiple files, but the one undesired side effect, is the filename prefacing the output. How can I suppress the filename outputs using only grep? $ grep -i lp lpNet* lpNet:This was printed via the internet using…
j0h
  • 15,365
46
votes
3 answers

How does this [t]ricky bracket expression in grep work?

I saw this one-liner recently: $ ps -ef | grep [f]irefox thorsen 16730 1 1 Jun19 ? 00:27:27 /usr/lib/firefox/firefox ... So it seems to return the list of processes with "firefox" in the data but leaving out the grep process itself,…
Thorsen
  • 866
1
2 3
49 50