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.

745 questions
149
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,591
57
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
  • 869
  • 1
  • 7
  • 14
49
votes
2 answers

grep "+" operator does not work

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

What does grep line buffering do?

Here's my command that I'm using in a script to grep real-time data. It doesn't seem to pull real-time data correctly as it just misses some lines. tail -f | fgrep "string" | sed 's/stuff//g' >> output.txt What would the following command…
Roboman1723
  • 2,915
  • 8
  • 23
  • 31
18
votes
4 answers

Recursive grep fails for *.c files

I tried to recursively search a pattern in all the .c files in the following way > grep -lr search-pattern *.c But got this as the output > grep: *.c: No such file or directory When I use this: > grep -lr search-pattern * I get plenty of . c…
Jay
  • 2,270
17
votes
3 answers

Why is my grep + regex not working?

I recently decided that enough was enough -- I was going to learn to use grep fluently. It's been all of three hours and I'm already stumped by this toy problem. I'm currently syncing a RAID5 array, the progress of which can be monitored by reading…
13
votes
2 answers

How do I use grep to find all the zip files in a directory?

I have a directory with over 1000 files, and a few of them are .zip files, and I want to turn them all into .tgz files. I want to use grep to make a list of file names. I have tried "grep *.zip" to no avail. Reading the man pages, I thought that *…
12
votes
2 answers

grep : how to color 2 keywords?

I know how to grep 2 keywords using 1 command, but I can only manage to color one of them in output . Here is my command: grep 'keyword1' file.log | grep 'keyword2' Only keyword2 is highlighted. How can I make keyword1 highlighted at the same time…
Raptor
  • 375
9
votes
2 answers

Grep ignore array of patterns

Since I learned some bash syntax, I have being very enthusiastic about its use in daily life. A famous command is grep. In case one with to grep something but ignore several files, the commands below MAY work. grep_ignore=("token_a", "token_b") grep…
8
votes
3 answers

how can one combine a series of grep statements piped together into one grep statement?

I would like to know if there is a way to combine a series of grep statements where the effect is to "and" the expressions rather than "or" the matching expressions. Demo below: ./script From one grep statement, I want output like this a b…
Keith Reynolds
  • 429
  • 3
  • 8
  • 18
6
votes
1 answer

How to avoid having newlines with grep -o for multiple match at the same line?

With grep -o, I have a new line for every match: # echo "a b a"|grep -o a a a How can I obtain the following result? # echo "a b a"|grep -o a a a
user123456
  • 2,378
6
votes
3 answers

How can I use the grep command to extract line which is the next line of greping line?

I have text file like (the specific part of the whole file); ! lat long elev (m) ! 44.5199005 11.6468000 50.4276 I need to extract second line and save them in another text file. The numbers are variable…
deepblue_86
  • 1,194
6
votes
3 answers

grep string from a pcap file

I'm trying to figure out the correct command syntax. I have a pcap file, and I want to use grep, and grep only to take out all of the uniq ip addresses from without the file So assuming the file is called capture.pcap and is in my home folder, what…
Giladiald
  • 239
  • 1
  • 4
  • 13
6
votes
1 answer

ack-grep: command not found after upgrade to Ubuntu 18.04

sudo apt-get install ack-grep gives ack-grep is already the newest version (2.22-1) but ack-grep gives ack-grep: command not found It was working fine in Ubuntu 16.04, before upgrading to 18.04
rigyt
  • 215
5
votes
4 answers

Find text file containing a given text ignoring new lines and spaces?

I have a string like: "thisissometext". I want to find all text files inside a given directory (recursively) that containg this string, or any variations of it with white spaces and/or newlines in the middle of it. For example, a text file…
a06e
  • 13,223
  • 26
  • 70
  • 104
1
2 3 4 5 6