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

learn more… | top users | synonyms

1
vote
2answers
610 views

pattern search and display the last occuring pattern?

I have a log file containing startup and shutdown times for everday. I want to see the last pattern pattern for startup and shutdown(which is located at the end of the file being updated everyday). ...
3
votes
1answer
1k views

How to use a value returned by a script in grep filter?

I'm on FreeBSD's csh. I want to form a row with domains of one user and then use this row to filter exim maillog to get only mail from/to this user's domains. I wrote a script to form a row from a ...
12
votes
2answers
48k views

Return only the portion of a line after a matching pattern

So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a ...
2
votes
3answers
1k views

Returning only the portion of a line after a matching pattern

I have a file (file_name) which contains exactly one occurance of the string Result:, at the start of a line. I want to print all the characters after the string Result: in that line until I encounter ...
3
votes
4answers
700 views

Find a string (like grep -q) within only a section of a file

I want to write some Bash that can verify that a string exists in a configuration file. I can't change the file format, it belongs to a different application. The file is subdivided into groups named ...
-2
votes
1answer
311 views

Linux “rpl” command doesn't replace text [closed]

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: ...
4
votes
2answers
829 views

grep caret appears to have no effect

I was under the impression that a caret symbol means "beginning of the line" with Extended POSIX regular expressions. However, when I use it with grep it behaves unexpectedly. #grep --version GNU ...
2
votes
2answers
1k views

How do I show all files in a directory except those that have a certain extension AND display them in multiple columns?

Since I write in Python a lot it's kind of annoying to see .pyc files all the time and I would like to just hide them at this point. I tried the following, but I can't seem to figure out how to get it ...
3
votes
1answer
631 views

grep and brackets in text

I store downloaded files in a log like this: [source] filename To avoid downloading a file more than once I grep for [source] filename before: if ! grep "$signature" downloaded.log > ...
0
votes
1answer
407 views

What does ^> mean in a grep pattern?

What does this command do? grep "<[^>]*>" inuux.xml What is searching for?
5
votes
1answer
2k views

What does \bi\b mean in a grep pattern?

What does this command do? grep "\bi\b" linux.txt What is it searching for?
4
votes
3answers
2k views

Show lines matching a pattern and the 4 lines before each

For example, from this file: CREATE SYNONYM I801XS07 FOR I8010.I801XT07 * ERROR at line 1: ORA-00955: name is already used by an existing object CREATE SYNONYM I801XS07 FOR ...
1
vote
1answer
3k views

grep directory names, filenames, and contents all at once?

I'm writing a module for drupal. Its functionality is contingent on the directory name, certain file names, and function names being identical. I'm troubleshooting now, and I wanted to to a search ...
1
vote
2answers
1k views

How to group grep results?

I have a file that contains results grouped into categories. For example: checking results for $var here are some results1 for $var status ok here are some results2 for $var status ok here are some ...
1
vote
5answers
988 views

Display output to console while grep is used

In vim I use the following command to compile a tex file: pdflatex\ \-file\-line\-error\ \-shell\-escape\ \-interaction=nonstopmode\ $*\\\|\ grep\ \-P\ ':\\d{1,5}:\ ' this works in terms of getting ...
1
vote
1answer
2k views

grep - recognize carriage return as new line [closed]

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 ...
2
votes
3answers
244 views

Omitting results containing '//' from grep searches

I'm trying to search a substantial C++ codebase for a single line that is outputing text to the terminal that I'd like to suppress. I have grepped for std::cout and have had around 40 different files ...
5
votes
2answers
8k views

Grep 'OR' regex problem

I am trying to use grep with a regex to find lines in a file that match 1 of 2 possible strings. Here is my grep: $ grep "^ID.*(ETS|FBS)" my_file.txt The above grep returns no results. However if I ...
0
votes
1answer
395 views

Printing file content with grep

Is it possible to print to the console all file content using only grep command? (wihtout cat, less, echo, more...)
5
votes
1answer
547 views

How can I search/browse in some process's memory?

I'm using MacOS X 10.7 and I'm not very familiar with unix. Is there a command for a search in some process's memory for a string?
1
vote
1answer
195 views

What special characters does grep parse by default? [duplicate]

Possible Duplicate: In a regular expression, which characters need escaping? I know there is the -E flag which treats the "search term" as a regular expression. However, it seems that even ...
12
votes
3answers
889 views

How can I redirect matching lines to a file, and non-matching lines to a different file?

Is there a script/program/utility already available for the following requirement in a optimised way? someCommand | tee >(grep "pattern" > LinesWhichMatch) | grep -v "pattern" > ...
7
votes
6answers
21k views

How to search for a word in entire content of a directory in linux

need to search for something in entire content I am trying: find . | xargs grep word I get error: xargs: unterminated quote How to achieve this?
12
votes
3answers
8k views

How to show lines after each grep match until other specific match?

I know that by using the "-A NUM" switch I can print specific number of trailing lines after each match. I am just wondering if it's possible to print trailing lines until a specific word is found ...
1
vote
1answer
850 views

Diff similar lines

I'd like to print a list of lines where the first word in two files is identical, and the rest of the words are not. Some complicated mess with comm, grep and cut would be possible, but hopefully ...
1
vote
2answers
1k views

Using grep to read a paragraph on Solaris

How can I grep a paragraph from a file in the Solaris operating system? I tried the -p option used in AIX, but it's not useful in Solaris. grep -p Accept is not working in Solaris. Is there any other ...
8
votes
3answers
6k views

How do I grep without leading whitespaces?

I'm greping through a large codebase, and leading whitespaces and tabulation seem to be quite annoying. Is there any way to get rid of it? grep -R "something" ./ E.g, instead of: foo/bar.cpp: ...
26
votes
2answers
15k views

How do I pass a list of files to grep

I am using find and getting a list of files I want to grep through. How do I pipe that list to grep?
2
votes
2answers
91 views

How do I execute a command on a given string in each line of a file?

Let's assume that I already have a file created. This file creation comes from the execution of a command. The contents of the file will be up to 4 different lines looking something like this: LUN ...
18
votes
4answers
7k views

What makes grep consider a file to be binary?

I have some database dumps from a Windows system on my box. They are text files. I'm using cygwin to grep through them. These appear to be plain text files; I open them with text editors such as ...
2
votes
4answers
682 views

Use “grep” to match text in multiple files

I have data in multiple files. I want to find some text that matches in all files. Can I use the grep command for that? If yes then how?
3
votes
3answers
2k views

executing multiple greps in a single find command

I want to use find command to find some files containing multiple patterns at the same time. I tried something like this: find . -name "*.xml" -exec grep -iH keyword1 + && grep -iH ...
6
votes
4answers
7k views

How to display line number while doing grep on a file

How to display line number while doing grep on a file. For example: grep CONFIG_PM_ADVANCED_DEBUG /boot/config-`uname -r
4
votes
2answers
3k views

Using grep -v on multiple arguments

Is there a simpler way to do this? grep -v foo file | grep -v bar There're probably very elegant ways to do it with egrep, but how to go with plain old grep? EDIT: grep -v 'foo\|bar' file seems to ...
7
votes
3answers
11k views

How to specify characters using hexadecimal codes in `grep`?

I am using following command to grep character set range for hexadecimal code 0900 (instead of अ) to 097F (instead of व). How I can use hexadecimal code in place of अ and व? bzcat archive.bz2 | grep ...
6
votes
2answers
4k views

grep surrounding characters of a match

I'm looking to do a find and replace within a giant database dump, and it's not doing what I think should happen. I'd like to grep for my target string in the file, and then see the surrounding 8 ...
2
votes
4answers
1k views

Why is grep -o -w not giving me the expected output on Mac OS X?

If I do echo foo bar baz | grep -o -w baz the output is foo bar baz (and an extra newline). The expected output would be baz as the -o option should only display the matched part. I'm using Mac OS X ...
3
votes
2answers
1k views

How to search for a string only in textfiles? (recursively)

I can list all the textfiles (by mimetype) in a folder with: find . -type f -print0 | xargs -0 file -i | fgrep -i text | sed 's/:$//g' 2>/dev/null | awk 'BEGIN {FS=": "} {print $1}' Ok. But how ...
8
votes
3answers
20k views

Searching for a string on multiple zip files.

I have a folder that contains about 200 zip files. Each zip file contains only one text file in it. I would like to search for a specific string in all the text files in all the zip files. I tried ...
2
votes
3answers
4k views

How to feed the results of date command into grep to filter results of another command

I need to use the result of a formatted date command (date +"%m/%d") as the grep filter to filter the results of another command that will display alerts on a system so that I only see alerts from the ...
2
votes
2answers
2k views

Regex : match 2nd and 3rd character

I was doing some exercises on regular expressions, but I can't seem to be able to crack this one : egrep in a file where the 2nd and 3rd character are the same. I tried : egrep '^..{2}' ...
2
votes
2answers
4k views

Add carriage return to output of `tail` while using `grep`

I'm looking to refactor the following command: tail -f production.log | grep -e "Processing " -e "compatible;" -e "Completed in " -e This is the output of the command: Processing ...
72
votes
5answers
50k views

What is the difference between `grep`, `egrep`, and `fgrep`?

Can any one tell me the technical difference between grep and egrep, and fgrep and provide a suitable example? When do I need to use grep over egrep and vice versa?
1
vote
4answers
732 views

tee and grep at the same time (shell)?

I'm trying to run a server that writes to $log (a txt file) and then find all the text in the logfile that starts with '[1]' and put it in another file. Here's my attempt. tee -a $log works along with ...
2
votes
4answers
5k views

Deleting Lines Containing a Specified String in Different Files

Suppose there are two files in web/ named foo.php and bar.php. The 1st line of foo.php is "sdajgeSTRINGdsad" and the 10th line of bar.php is "gdfhu98324STRING". The task is to first locate these two ...
2
votes
1answer
142 views

Is there a way to get the effect of combining grep -v with grep -A?

Is there a way, either with grep or something else, to (in effect) combine grep -v and grep -A? That is, rather than include everything for x lines after a string, exclude everything. Quick reminder ...
5
votes
2answers
2k views

Pattern Matching Exclude Duplicate Characters

Is there a regular expression for the following that matches characters in a character set but only once? In other words, once a character is found, remove it from the set. If grep cannot do this, ...
2
votes
2answers
129 views

In-place substitution for lines matching some pattern in a given set of files

Following on from my previous question: Remove slashes/parent paths from filenames inside CSS and Javascript content I arrived at the following command which replaces any filenames in these ...
3
votes
3answers
320 views

find first line beginning with <keyword> following <other-keyword>

let's present my problem to explain better. I'm using cygwin, the installation is based on a setup.ini with the following format: @ package-name sdesc: "short description, on one line" ...
24
votes
3answers
28k views

How to search text throughout entire file system?

Assuming that the grep tool should be used, I'd like to search for the text string "800x600" throughout the entire file system. I tried: grep -r 800x600 / but it doesn't work. What I believe my ...