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.

748 questions
512
votes
11 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,835
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 + <tab> ). 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
157
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,671
111
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 there any…
Ant's
  • 3,950
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,490
72
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 75447A831E943724DD2DE9959E72EE31…
BeMy Friend
  • 1,253
69
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
  • 795
64
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
  • 939
62
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,623
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…
53
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
  • 533
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
52
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 the lp…
j0h
  • 15,531
51
votes
2 answers

grep "+" operator does not work

This ls -l /var/log | awk '{print $9}' | grep "^[a-z]*\.log." outputs this: alternatives.log.1 alternatives.log.10.gz alternatives.log.2.gz alternatives.log.3.gz alternatives.log.4.gz alternatives.log.5.gz alternatives.log.6.gz alternatives.log.7.gz…
Marko
  • 792
48
votes
3 answers

Modifying the color of grep

When I grep something, the result is always in red. I know that the command grep --color prints the result in color, which by default is red. Can I change the color?
user833907
1
2 3
…
49 50