grep a Unix command-line utility which searches input passed to it for lines matching a regular expression, and prints the results.

learn more… | top users | synonyms

9
votes
2answers
9k views

How to Combine find and grep for a complex search? ( GNU/linux, find, grep )

I'm trying to do a text search in some files that share a similar directory structure, but are not in the same directory tree, in GNU/Linux. I have a web server with many sites that share the same ...
6
votes
4answers
5k views

Command line tool to search phrases in large number of pdf files

I'm using Opensuse 10.3 and like to know command line tools to search phrases in large number of pdf files inside a directory. In Windows XP the Explorer search allows this but is too slow. Is there ...
40
votes
7answers
85k views

Command prompt (Windows 7) grep equivalent?

Is there a command prompt (Windows 7) grep equivalent? That is, I want to filter out the results of a command: Bash use: ls | grep root What would it be from a Windows command prompt?
8
votes
3answers
13k views

Grep multiline pattern

How do I search for a phrase over multiple lines? E.g. Lets have the phrase "my ice tea" then it may be wrapped in text files: as js skdfh dfh djh sf my ice tea. grep will not match since there is ...
6
votes
4answers
8k views

Mac OS X search and replace tool with regular expression support

I'm looking for a regular expression based search/replace GUI tool that is able to handle multiple files/subdirectories, something like grepWin but for Mac OS X. PS. I'm aware of grep and I don't ...
6
votes
1answer
2k views

Regex for “or” of multiple words in grep

[Computer]$ grep "foo|bar" filename I understand the above command should return each line in filename where there exits "foo" or "bar". The man pages confirms | as the Regex or symbol and the code ...
3
votes
3answers
2k views

How can I grep in source files for some text?

At the moment I'm using two commands, I'm sure there must be a better way... wim@wim-acer:~/ffmpeg$ find . -name "*.h" -print0 | xargs -0 grep -i invalid\ preset wim@wim-acer:~/ffmpeg$ find . -name ...
2
votes
3answers
161 views

grep -c gives inconsistent outputs

I am trying to determine the number of processes that are running via the following command line: ps aux | grep -c 'Xvfb :1' When the process "fiji :1" is not running I sometimes get a value of 0 ...
4
votes
1answer
6k views

Grep command, to remove lines containing a specified word

I want to use grep in the following way: grep -v "END","EXPDTA" 1bmz_model1.pdb > 1bmz_model.pdb I want the grep command to remove the lines which contain the words "END" and "EXPDTA", but all i ...
2
votes
7answers
172 views

strange behaviour of grep in UNIX

When I type the command $ grep \\\\h junk then the shell should interpret \\\\h as \\h - as the two pairs of \\ each become \ . grep in turn, should interpret \\h as \h as \\ becomes \, so grep ...
-1
votes
1answer
365 views

Linux “rpl” command doesn't replace text

I'm using rpl program in linux to replace date( with pdate( in some files. But it says A Total of 0 matches replaced in 1 file searched. while grep output for date( is: ...
82
votes
5answers
17k views

Less and Grep: Getting colored results when using a pipe from grep to less

I use the --colour option of grep a lot, but I often use less as well. How can I pipe grep results to less and still preserve the coloring. (Or is that possible?) grep "search-string" -R * --colour | ...
15
votes
5answers
7k views

Grep tool for XML

I am looking for a good tool to perform grep-like operations on XML - for example, extract certain attributes only. Grep itself can't handle it - any DFA-equivalent tool can handle only non recursive ...
7
votes
7answers
10k views

Monitoring a file until a string is found

I am using tail -f to monitor a log file that is being actively written to. When a certain string is written to the log file, I want to quit the monitoring, and continue with the rest of my script. ...
12
votes
5answers
9k views

Writing “tail -f” output to another file

As a continuation from my last post where I have used grep & tail -f to find occurences of "rare" events. I would like to record this in another file. I've tried turning tail -f log.txt | ...
8
votes
9answers
6k views

grep all .java files in a directory for a particular string

How would I search all .java files for a simple string (not a regex) in the current directory and all sub-directories on Mac OS X? I just want to print a list of file and directory names that match.
7
votes
3answers
6k views

grep for “term” and exclude “another term”

I am trying to build a grep search that searches for a term but exludes lines which have a second term. I wanted to use multiple -e "pattern" options but that has not worked. Here is an example of a ...
4
votes
2answers
13k views

How to grep a log file within a specific time period

I have a log file, each line in the log is prepend with a date, like so: 2012-03-06 11:34:48,657 blah blah blah... How do I grep this file and get only the lines from 8am to 11pm only? My ...
9
votes
6answers
3k views

Unicode grep for Windows

Is there a Unicode-aware grep for Windows 32-bit?
7
votes
1answer
3k views

How can I grep with color in Mac OS X's terminal?

I recently found that on Mac OS X I can set this up in my shell ~/.profile so that when I use grep it will print the matches in color (white one red). alias grep='GREP_COLOR="1;37;41" LANG=C grep ...
5
votes
2answers
790 views

grep - match anything but given filetype

I want to clean out my music library so I don't get any more "search for suitable plugin" messages from Rhythmbox when it sutubles across some WMA-Relic. I have the tools, but now I want to FIND ...
5
votes
7answers
6k views

How do I search for a string in a PHP file using `grep`?

I am searching for a class declaration on a site with hundreds of PHP files. How can I do this in the current folder and subfolders using grep? I tested cding to the folder and then something like ...
4
votes
1answer
159 views

Get additional data around match from grep

I'm wondering how to improve my grep use when being confronted with files with very long lines. Imagine something like "packed" JavaScript files that only have 1 line. Sometimes files like that spit ...
2
votes
1answer
602 views

Why does grep return no results (list all files in directory)

I'm trying to count all files in a directory that match a pattern, recursively, using ls: ls -R | grep *.{cpp,h} | wc However, I get: zsh: no matches found: *.cpp ls -R does return results, ...
0
votes
2answers
97 views

Grep values from nethog and netperf

I need to monitor the network activities of a process and the bandwidth of the connection. So I decided to use nethog and netperf combine with grep and awk to write the values to a file. nethog ...
9
votes
4answers
6k views

Ubuntu grep, find etc: “Permission denied” and “No such file or directory” output

When I grep or find something I always get annoyed by the "Permission denied" and "No such file or directory" notice, smth like that: johndoe@johndoe-desktop:/$ grep -rnP 'YII_CORE_PATH' ./ | grep -v ...
8
votes
5answers
3k views

How is \$ being interpreted by grep?

When I write $ grep \$ then whatever I type on terminal, is matched and printed on terminal. How is \$ being interpreted?
7
votes
6answers
3k views

Using an index to make grep faster?

I find myself grepping the same codebase over and over. While it works great, each command takes about 10 seconds, so I am thinking about ways to make it faster. So can grep use some sort of index? I ...
7
votes
4answers
5k views

how to grep and print the next N lines after the hit?

I would like to grep for an occurrence in a text file, then print the following N lines after each occurrence found. Any ideas?
2
votes
2answers
277 views

ack + tool like grep (problem )

I use the ack tool to find string or IP address in file system but please see the follwoing why ack not find the IP = 10.45.45.130 under /etc/sysconfig/* the IP = 1:10.45.45.130 exist under network ...
1
vote
1answer
374 views

Simulate pgrep using plain grep

How can I do pgrep -U someUserName using just ps and grep? I.e. not count on pgrep being set in a system?
1
vote
1answer
316 views

What is the best way to undelete some photos on Linux? Is there any way to use foremost to only recover files that only contain some text?

I accidentaly deleted some digital photos I had recently taken, and I wanted to undelete them. I found out about Foremost, and it allows me to recover jpg files, but will fo that with all of the ...
0
votes
1answer
107 views

Show starting with a special line until a special line regex for Linux tail command

I use that notation at my log files: [something-something] somethings are necessary and variable length characters and numbers. My special log file includes line that has characters explained above. ...
0
votes
1answer
62 views

Searching Multiple Terms

I know that grep -E 'termA|termB' files allows me to search multiple files for termA OR termB. What I would like to do instead is search for termA AND termB. They do not have to be on the same line as ...
-1
votes
2answers
101 views

Show matched lines for a given regex at Linux

I use that notation at my log files: [something-something] somethings are necessary and variable length characters and numbers. My special log file includes line that has characters explained above. ...
-1
votes
2answers
1k views

Getting this simple regular expression to match in grep

I want to match a quote, 2, a space, and any character that is not a literal dot. This is using GnuWin32 grep. Not Cygwin's grep. C:\>echo "2 008abc.html" | grep -oiP \"2 [^.] grep: [^.]': No ...