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

learn more… | top users | synonyms

8
votes
2answers
10k 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
316 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
307 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
135 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
1k 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
489 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
339 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
307 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
4answers
664 views

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 ...
2
votes
2answers
999 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
2k 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 ...
6
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.
7
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
425 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
10k 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
53 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 ...
4
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
406 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
1k 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
228 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
444 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
169 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 ...
0
votes
2answers
474 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
2k 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
468 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
184 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
9k 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
396 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
984 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
6k 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
620 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
2k 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
132 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 ...
2
votes
4answers
2k views

Outputting grep to multiple variables

I what to have bash script to grep output to multiple variables but have no idea how to do that: command |grep bla > $result1 $result2 etc... Any ideas? S
1
vote
4answers
2k views

ls | grep regex, ignore files with .tab,

I know some regex but I don't know how to get this to work. I want to list all files that don't have .tab. and don't have ~ at the end of the filename and aren't a .o (or .bin) I can list all the ...
11
votes
2answers
8k views

When to use single-quote, double-quote in grep?

While trying to search for a simple pattern "hello" in a file, all the following forms of grep work: grep hello file1 grep 'hello' file1 grep "hello" file1 Is there a specific case where one of ...
0
votes
3answers
1k views

Get results from grep in the order they appear?

I'm trying to grep a log file to only show lines that match a certain session ID. Thus far, it works great. However, when I get the results of my grep command, I'm not getting the entries in the ...
1
vote
3answers
971 views

Shell Script: How do I turn “virsh list | grep MediaWiki” into an if condition?

I'm trying to determine if a given Virtual Machine is running using a shell script. The command "virsh list | grep MediaWiki", when run manually, returns one line if the Virtual Machine is running, ...
2
votes
2answers
4k views

ps ax | grep java with no wrapping in the terminal?

Is there a way to execute ps ax | grep java without it wrapping on the terminal?
2
votes
1answer
2k views

How do I show filenames only after a keyword grep search?

I currently have n data files in a directory where each file has at most 1 line of very long data. My directory structure is director/ data1.json data2.json data3.json I know that at ...
3
votes
2answers
664 views

Local full text index for a directory tree, a quicker alternative for grep -R

I have a large directory tree of source files. I want to search around all these files. My first instinct is to use grep -R or ack, but either way they just sequentially read all the files. Is there ...
3
votes
2answers
2k views

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

Linux Command to find Strings in Binary or non ascii file

Is there any linux command to extracts all the ascii strings from an executable or other binary file? I suppose I could do it with a grep, but I remember hearing somewhere that such a command existed? ...