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

learn more… | top users | synonyms

2
votes
5answers
1k views

Find files containing a string on the whole filesystem

I need to find all the instances of a given string in the whole filesystem, because I don't remember in which configuration files, script or any other programs I put it and I need to update that ...
1
vote
1answer
445 views

Need help on awk/sed/ perl pattern with regex / grep

Sample file output from grep file1:my $dbh = DBI->connect("dbi:mysql:$database_name", $DB_USER, $DB_PASSWD) file2:($dbc,$rc) = mysql_connect($mysql_host,$mysql_user,$mysql_password); The awk ...
5
votes
2answers
1k views

List top 404 URLs in Apache access_log

I'm looking for a command to list the 10 or 20 top 404 error URLs out of my apache access_log. Can anyone help me with this? thanks
1
vote
4answers
127 views

Locate a particular string in a directory

I want to do the following: cat *.xml | grep some_string_here This tells me if a particular string exists in an xml file in a directory. Unfortunately it does not tell me which file. how can I do ...
0
votes
2answers
280 views

How to strip logfile with grep to remove various dispensable information?

My logfile has the following format: Dec 26 13:11:48 192.168.1.1 kernel: ACCEPT IN=br0 OUT=vlan1 SRC=192.168.1.2 DST=74.125.43.147 LEN=44 TOS=0x00 PREC=0x00 TTL=63 ID=9312 DF PROTO=TCP SPT=11733 ...
1
vote
4answers
254 views

grep/list bash recursive

parts = grep "/root/backups/*" for part in $parts do echo $part rm -rf $part #delete done I basically need to iterate through a folder and return every item in the folder using a Bash ...
1
vote
3answers
2k views

tail -f and then exit on matching string

I am trying to configure a startup script which will startup tomcat, monitor the catalina.out for the string "Server startup", and then run another process. I have been trying various combinations of ...
2
votes
1answer
4k views

grep range of dates - apache log

I'm wondering how could I do the following greps: grep Apache log only for a range of dates, assume from 5/Nov/2010 to 5/Dec/2010 and grep Apache log starting from `15/Nov/2010 until the last ...
2
votes
4answers
2k views

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 ...
0
votes
2answers
195 views

Search multiple strings from multiple files

How to search multiple strings from multiple files with a single command. May be using grep or find or if there is any other in Linux or Solaris
0
votes
2answers
356 views

Getting data from log file

I'd like to get the memory usage from the following log entries. It's the number right after 200 for the URL. I'd like to get a list of highest memory usage first, like top 10. I think I'd use ...
13
votes
2answers
15k views

Getting the last match in a file using grep

What's the best way of getting only the final match of a regular expression in a file using grep? Also, is it possible to begin grepping from the end of the file instead of the beginning and stop ...
0
votes
2answers
96 views

Recover programmation source files

I've source code files (Java and C++) to recover from a broken RAID 1+0 array, I've been able to access the virtual drive with an other server but the ReiserFS partition can't be recovered with ...
0
votes
2answers
330 views

Passing a file with multiple patterns to grep

Let's say we have two files. match.txt: A file containing patterns to match: fed ghi tsr qpo data.txt: A file containing lines of text: abc fed ghi jkl mno pqr stu vwx zyx wvu tsr qpo Now, I ...
0
votes
1answer
313 views

Egrep Regular Expression to suppress certain lines

i try to use the following command to suppress certain lines of output that contain the strings "DST=192.168.1" or "DST=192.168.2" tail /var/log/messages | egrep -v -e ...
0
votes
1answer
145 views

How to display results without two first lines

When I run some bash command it returns 2 .. n lines of text (n is different each time, may contain blank lines). How to filter the output to display the result skipping lines 1 and 2? e.g. $ ...
1
vote
2answers
2k views

grep'ing through mailq

I want to filter some of the mail IDs returned by mailq (Postfix). However, the format is not very "grep-friendly", since the information for a single mail spans multiple lines: 9F701869D2 1356 ...
1
vote
1answer
659 views

sed can't find a file that obviously exists

I run the following command which comments out all lines that contain the text "dlclose" grep -lIR "dlclose" . | grep -v ".svn" | xargs sed -i "s/.*dlclose.*/\/\/&/g" However, sed claims that ...
1
vote
1answer
362 views

Comment all lines matching some pattern

I need to comment out all lines containing "dlclose" for each file in the current directory and any sub-directories (recursively). This is my best guess so far given what I was able to find out from ...
2
votes
1answer
427 views

Find occurrences of a file of words in a dictionary

I have a number of search logs that I want to compare against certain dictionary files. Once I process the search logs to filter out certain entries and get all the search terms into separate lines, ...
2
votes
2answers
1k views

How can I remove malware code in multiple files with sed?

I've this malware code in so many .html and .php files on the server. I need to remove them using sed -i expression search all files under directory /home/ find infected files remove the code by ...
0
votes
3answers
2k views

How to filter http request URL by mime type?

I'm trying to make a shell script which filters http request URL by mime type. (ex: image/jpg image) I used tcpdump to sniff packets and grep to filter http headers. This is my current command: echo ...
1
vote
6answers
2k views

grep question, how to filter several type of patterns?

I'm console newbie. As I know, matching multiple patterns like this: aaa|bbb But, | character is pipe on console, so how can I specify those multiple patterns for grep?
2
votes
2answers
3k views

Send email based on grep results

I'm using WebInject (CLI not GUI) to test out online web services. I was going to go with a third party until I found this little gem and realized what I could save... What I want to accomplish is to ...
7
votes
3answers
3k views

echo based on grep result

I need a one liner which displays 'yes' or 'no' whether grep finds any results. I have played with grep -c, but without success.
8
votes
4answers
2k views

Searching for literal “> \” using ack-grep

I am looking for lines that literally have a greater than character (a ">") followed by a space followed by a backslash character (a "\") i.e., a line with this: > \ I thought escaping would allow ...
0
votes
2answers
430 views

New 64 bit linux system has regular processes (ps, grep etc) taking up way too much VIRT mem

We just moved from a 32-bit machine to a 64-bit machine. We have quickly ran out of memory despite the new boxes have twice as much ram as the old boxes. Running a simple ps command will illustrate ...
4
votes
1answer
13k views

How to view hidden files using Linux `find` command

On a Linux server, I need to find all files with a certain file extension in the current directory and all sub-directories. Previously, I have always using the following command: find . -type f | ...
1
vote
2answers
54 views

UNIX tool to dump a selection of HTML?

I'm looking to monitor changes on websites and my current approach is being defeated by a rotating top banner. Is there a UNIX tool that takes a selection parameter (id attribute or XPath), reads HTML ...
5
votes
6answers
2k views

How to remove a tagged block of text in a file?

How can I remove all instances of tagged blocks of text in a file with sed, grep, or another program? If I have a file which contains: random text // START TEXT internal text // ...
1
vote
3answers
419 views

grep/search for multiple lines in a file

Let's say I have a file with a long nested array, that's formatted like this: array( 'key1' => array( 'val1' => 'val', 'val2' => 'val', 'val3' => 'val', ), ...
3
votes
4answers
2k views

“watching” a log on FreeBSD vs Linux

On Linux systems I can watch -n1 tail /var/log/whatever.log or watch -n1 grep somestuff /var/log/whatever.log To show updates to a log every 1 seconds. On FreeBSD however, the watch command does ...
1
vote
3answers
232 views

how to grep out a particular line from a file

How can I grep out a particular line from a file in a folder. Basically I have a folder /my/cool/folder/myfile.txt I know it has line: I am cool lkasjdfaksldfj How can I grep on that file so the ...
2
votes
2answers
464 views

Advanced grep, where string doesn't begin with a URL

I'm seeing tons of error logs on our site that are looking for favicon.ico. The favicon is now hosted off of amazon S3 but it appears somewhere we still have a link to the old one that I can't find ...
2
votes
2answers
174 views

greping files question

I've been using grep to run a few PII scans and while it's finding results, it's indeed finding too many false positives. Is there a way that I can tell grep not to trigger a match for a file unless ...
1
vote
2answers
700 views

Spamassassin one-liner to tag & move mail with an X-Spam-Flag: YES to a new directory?

Say you have a directory with tens of thousands of messages in it. And you want to separate the spam from the non-spam. Specifically, you would like to: Run spamassassin against the directory, ...
1
vote
3answers
3k views

How do I extract the matching part of a regex on Solaris

GNU's grep has the option --only-matching, which prints just the matching region of a regular expression. I'm on a Solaris 5.10 box without any GNU tools installed, and I'm trying to achieve the same ...
1
vote
2answers
481 views

repeated curl + grep on macosx occasionally giving bad results?

Running macosx 10.6.2, I am seeing some extremely weird behavior with a script which repeatedly calls curl -o (file) and then greps for a certain string within it. Occasionally grep returns 1 (not ...
0
votes
4answers
5k views

non greedy grep command on ubuntu?

I'm building a script which filters out all our translatables from our template system. the problem i'm facing is the occasion where 2 translatables are on one line. These are 2 example lines from a ...
0
votes
4answers
187 views

Grep a word from a file

How can i grep a nearer word from a file ? E.g 04-02-2010 Workingday 05-02-2010 Workingday 06-02-2010 Workingday 07-02-2010 Holiday 08-02-2010 Workingday 09-02-2010 Workingday I stored ...
2
votes
1answer
1k views

How to use grep commend with variable

How can i use grep commend with variable ? I stored ' Feb 1 ' (future it will be changeable) to variable 'date'. Now i want to grep this variable 'date', How can i do this ?
2
votes
2answers
11k views

grep to find files that contain a string greater than x characters long?

Is it possible to locate files in a directory that have strings (with no spaces) longer than x length?
2
votes
3answers
412 views

How to grab a word from a file using sed or grep

I am trying to pull a piece of text from a file to use as input for the next command. The word always starts with "JID_" and then some random numbers/characters after that. For example : ...
0
votes
1answer
1k views

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 ...
8
votes
4answers
8k views

Fast extraction of a time range from syslog logfile?

I've got a logfile in the standard syslog format. It looks like this, except with hundreds of lines per second: Jan 11 07:48:46 blahblahblah... Jan 11 07:49:00 blahblahblah... Jan 11 07:50:13 ...
0
votes
1answer
3k views

Grep date with regex

I have files with lines in the following formats: . . . 12/16/09 17:56:30.211 rest of line... . . . 12/17/09 05:34:10.809 rest of line... . . How do I grep the lines out of this file that are ...
0
votes
2answers
635 views

Apache Logs / Grep Command Help Needed

I need to be able to see all requests made by an IP in a given day. I'm not familiar with grep and was wondering if anyone could give me a hand.
2
votes
2answers
3k views

How do I make (non-gnu-)grep ignore binary files?

Hey, I am on a HP-UX server here. When recursively grepping a directory tree, I have problems when the tree also contains binary files: grep treats them as text files and displays very long lines ...
4
votes
3answers
3k views

How can i send /var/mail/root again?

Through some missconfiguration i've a lot of emails in /var/mail/root and /var/mail/www-data How can i "loop" over these files and send each mail another time? Thanks in advance!
1
vote
1answer
134 views

Matches in color, others just shown

I'm just trying to get grep to show all the lines, but the ones that match should have the matching text colored. Specifically I need this for something like this: tail -f file.log | grep --color ...