Questions tagged [grep]

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

Filter by
Sorted by
Tagged with
9 votes
5 answers
6k views

Combine multiple unix commands into one output

I need to search our mail logs for a specific e-mail address. We keep a current file named maillog as well as a week's worth of .bz2 files in the same folder. Currently, I'm running the following ...
Ben McCormack's user avatar
8 votes
9 answers
17k views

How to grep the IP address from ifconfig output

Following is my ifconfig output eth0 Link encap:Ethernet UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:...
Registered User's user avatar
0 votes
1 answer
1k views

Move all images in folder to subfolder, and update all references to those images to their new location?

I have a folder which contains a ~50 text files (PHP) and hundreds of images. I would like to move all the images to a subfolder, and update the PHP files so any reference to those images point to the ...
Professor Frink's user avatar
2 votes
4 answers
2k views

Is there a simple command-line HTTP proxy that outputs to STDOUT?

Is there a command-line HTTP proxy that outputs to STDOUT so I can use it with Unix pipes? I want to do something like this: Start the proxy at the command-line: $ proxy -p 8888 | grep "Text I'm ...
richardkmiller's user avatar
1 vote
2 answers
2k views

finding a group of string common in two files

I have used diff command in past.I faced a situation to which I did not had a clue here are some text strings (which can be stored in a file) CONFIG_XEN=y CONFIG_XEN_PVHVM=y ...
Registered User's user avatar
0 votes
4 answers
3k views

how to find a text string which may be present in some unknown file in entire filesystem

I am stuck up with a problem I have a line 'something' in some file. In which file is this line that I have forgotten. In the entire root file system I would like to find out which file and where is ...
Registered User's user avatar
2 votes
5 answers
5k 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 ...
Fabio's user avatar
  • 1,299
1 vote
1 answer
668 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 ...
Jayakumar K's user avatar
8 votes
2 answers
7k views

List top 404 URLs in Apache access_log [closed]

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
tykho's user avatar
  • 81
1 vote
4 answers
135 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 ...
Sid Kshatriya's user avatar
0 votes
2 answers
460 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 DPT=...
NES's user avatar
  • 215
1 vote
4 answers
313 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 script....
James's user avatar
  • 171
2 votes
3 answers
6k 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 ...
Patrick's user avatar
  • 192
6 votes
1 answer
13k 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 log ...
Charles's user avatar
  • 63
3 votes
4 answers
3k 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 ...
Chenna V's user avatar
  • 171
0 votes
2 answers
621 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
Ramesh Kumar's user avatar
  • 1,780
1 vote
2 answers
486 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 ...
Ben's user avatar
  • 3,880
93 votes
5 answers
190k 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 ...
Acorn's user avatar
  • 1,097
0 votes
2 answers
115 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 ...
Alexandre Lavoie's user avatar
1 vote
2 answers
536 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 want ...
Michael Goldshteyn's user avatar
0 votes
1 answer
370 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 'DST=(192\.168\.1\.1)|DST=(192\....
user avatar
0 votes
1 answer
182 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. $ ...
takeshin's user avatar
  • 1,481
2 votes
4 answers
5k 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 ...
Heinzi's user avatar
  • 2,237
1 vote
1 answer
3k 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 ...
user50914's user avatar
  • 121
1 vote
1 answer
1k 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 ...
user50914's user avatar
  • 121
2 votes
1 answer
2k 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, ...
Chris Henry's user avatar
  • 1,562
3 votes
6 answers
1k views

Distributed grep [closed]

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 ...
Ran's user avatar
  • 191
2 votes
2 answers
2k 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 ...
user47556's user avatar
  • 539
0 votes
3 answers
3k 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 ...
Eonil's user avatar
  • 10.6k
5 votes
6 answers
18k 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?
Eonil's user avatar
  • 10.6k
2 votes
2 answers
7k 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 ...
JohnyD's user avatar
  • 1,624
7 votes
3 answers
9k 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.
takeshin's user avatar
  • 1,481
9 votes
4 answers
6k 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 ...
Stephen Gornick's user avatar
0 votes
2 answers
467 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 ...
user42980's user avatar
42 votes
3 answers
117k 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 used the following command: find . -type f | grep -...
Tom's user avatar
  • 4,367
1 vote
2 answers
65 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 ...
jldugger's user avatar
  • 14.5k
6 votes
6 answers
5k 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 // END ...
EmpireJones's user avatar
1 vote
3 answers
994 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', ), '...
GSto's user avatar
  • 391
4 votes
6 answers
8k 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 ...
Cory J's user avatar
  • 1,588
1 vote
3 answers
661 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 ...
user avatar
2 votes
2 answers
585 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 ...
Ben's user avatar
  • 3,880
2 votes
2 answers
250 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 ...
tearman's user avatar
  • 425
2 votes
2 answers
2k 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, ...
ane's user avatar
  • 171
1 vote
3 answers
6k 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 ...
brianegge's user avatar
  • 1,074
1 vote
2 answers
575 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 ...
akaioi's user avatar
  • 139
0 votes
4 answers
7k 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 ...
ChrisR's user avatar
  • 262
1 vote
4 answers
270 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 above ...
Kumar's user avatar
  • 823
2 votes
1 answer
3k 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 ?
Kumar's user avatar
  • 823
8 votes
2 answers
32k 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?
sbuck's user avatar
  • 391
2 votes
3 answers
555 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 : ...
DellServerGeek's user avatar

1
3 4 5
6
7