Questions tagged [grep]

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

The grep utility searches a pattern (regular expression) in a text file. There are many options to control how matches are performed and how to display matches.

External references

Tutorials

Further reading

See also grep on Unix & Linux Stack Exchange for more detailed reading.

326 questions
3
votes
1 answer

How to find file which have not specific content?

I have a lot of files which already have SPF records defined grep -i v=spf *.db /var/named/domain.com.db domain.com. 14400 IN TXT "v=spf1 +a +mx +ip4:XXX.XXX.XXX.XXX ?all" And want to find all files without SPF records. Some hints?
3
votes
4 answers

How to properly pipe find with grep and cp in this use case

I am interested in recursively grepping for a string in a directory for a pattern and then cp'ing the matching file to a destination directory. I thought I could do something like the following, but it doesn't seem to make sense with linux's find…
imaginative
  • 1,971
  • 10
  • 32
  • 48
3
votes
2 answers

How can I use grep to find the most frequently recurring errors in my log file?

I've got a PHP application that is generating large amounts of warnings and notices in the log file.. I'm fixing these one at a time. I would like to be able to fix the most frequently occurring first in order to maximize the amount of effect my…
Edward Tanguay
  • 1,209
  • 4
  • 22
  • 31
3
votes
3 answers

How can I count the number of lines matching a pattern returned from a linux command

How can I count the number of lines matching a pattern returned from a linux command I want the number of lines returned beginning with 'foo' , so if I pipe the output to grep will this work? cat | grep -c ^foo
Dave
  • 367
  • 2
  • 5
  • 11
3
votes
2 answers

Is there a way to find a specific word in all files/folders in Linux?

I usually use grep word * while being in a folder which includes files that have that word. But in this folder i also have folders which under them there are files that have that word, what is the correct command for this matter please? Thanks
Itai Ganot
  • 10,644
  • 29
  • 93
  • 146
3
votes
2 answers

Extracting a line section of mysql backup using sed

I occasionally need to extract a single record from a mysqlbackup To do this, I first extract the single table I want from the backup... sed -n -e '/CREATE TABLE.*usertext/,/CREATE TABLE/p' 20120930_backup.sql > table.sql In table.sql, the records…
carpii
  • 541
  • 2
  • 4
  • 12
3
votes
1 answer

grep recursive exclusive search

I have text I want to recursively search in mydir/. I would normally type grep -r "text to find" mydir/" but what would I type if I wanted to search all the files except a specific one? For example, I do not want to search the file "myfile.txt" but…
dukevin
  • 1,630
  • 3
  • 18
  • 25
3
votes
4 answers

bash : "set -e" and check if a user exists make script exit

I am writing a script to install a program with Bash. I want to exit on error so I added set -e to the beginning of my script. I have to check if a user exists inside of my script. To do this I am using grep ^${USER}: /etc/passwd. If the user…
Ahmed Laatabi
  • 133
  • 1
  • 5
3
votes
2 answers

Grepping through the results of apachectl -S

I have a server with about 300 virtual hosts. When I want to make sure a specific httpd.conf file is loaded into the Virual Host config and the syntax is correct, I run apachectl -S. The problem is, though, I get a ton of output. I've tried…
CamelBlues
  • 303
  • 4
  • 10
3
votes
2 answers

egrep matching group not printing?

I'm trying to create a bash script that will grep lines from a file using egrep. I've created the regex that should group the information I want, the issue is trying to get the output. I've been testing it with the following command but nothing is…
krizzo
  • 387
  • 2
  • 5
  • 16
3
votes
3 answers

grep - recognize carriage return as new line

I want to search a webserver running unix for php-files containing a specific string. Usually I use these commands to accomplish this: find . -name "*.php" -print0 | xargs -0 grep -H -i "the string to search for" This will find any php file…
quano
  • 131
  • 1
  • 4
3
votes
4 answers

grep multiple file types recursively

I am trying to figure out how to search for "_iterator_tag" string in all sub directories recursively and in files with extensions .cpp, .h, .hpp, .cxx, .inl for now all I can do is search each of these file types separately as below grep -R…
Chenna V
  • 171
  • 1
  • 5
3
votes
6 answers

Distributed grep

Is there a solution for a distributed grep? here's the story: I have a bunch of web servers and want to query their application logs (I'm using tomcat, if it matters). I don't want to have to copy the files to a common storage, they are too big,…
Ran
  • 191
  • 1
  • 4
3
votes
2 answers

Redirect Linux terminal to clipboard

Is it possible to redirect the output of your terminal in linux to the clipboard? Right now I am using Ubuntu 9.10 and I simply right click and "copy" the selected text. It would be a lot easier if I could go like this... grep sometext myfile ||…
benstpierre
  • 265
  • 1
  • 3
  • 7
2
votes
1 answer

How does one simulate the old unix grep -S strict functionality in linux

I am grepping the output of a command and I wish to only return specific, strict results. I remember some iteration of grep had a strict option -s/--strict. For example, grep -s bytes would only return entries which mentioned the word "bytes" and…
Nathan Milford
  • 792
  • 2
  • 10
  • 21