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

learn more… | top users | synonyms

4
votes
6answers
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
248 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
493 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
180 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
974 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
4k 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
492 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 ...
1
vote
4answers
196 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
15k 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
426 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 : ...
1
vote
2answers
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 ...
10
votes
4answers
9k 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
5k 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
665 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 ...
8
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
135 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 ...
13
votes
2answers
16k 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
2k 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
1k 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?
7
votes
2answers
4k 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
829 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 ...
19
votes
5answers
28k 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?
3
votes
6answers
9k views

Don't need the whole line, just the match from regular expression

I simply need to get the match from a regular expression: $ cat myfile.txt | SOMETHING_HERE "/(\w).+/" The output has to be only what was matched, inside the parenthesis. Don't think I can use ...
1
vote
3answers
3k views

SED Find & Replace w\ Regular Expressions

Alright, So i'm confused & out of ideas. I'm trying to replace all the old IP addresses with a new one. find -type f | grep \.php$ | xargs sed -r -i "s/(\'|\")(localhost|127.0.0.1|10.0.32.4|10.0....
2
votes
9answers
2k views

How to reproduce grep's --recursive option in an old version of grep

I am working on an ancient UNIX whose grep lacks the -r/--recursive option. I need to find an error that our application is causing, but I do not know which log file our application is writing ...
9
votes
7answers
9k views

How do i get the default gateway in LINUX given the destination?

I'm trying to get the default gateway, using the destination 0.0.0.0 i used this command: netstat -rn | grep 0.0.0.0 and it returns this list: Destination - Gateway - Genmask - Flags - ...
1
vote
4answers
476 views

Unable to grep sourced Files in Vim

I have files which I source in my files. I want to search them, when I am at a file which have these sources. I run unsuccessfully !bufdo grep source and !bufdo grep source % Example of ....
1
vote
1answer
111 views

ignoring errors in find / output

how do I filter out permissions errors out of find / | grep foo output?
54
votes
12answers
83k views

Do you have any useful awk and grep scripts for parsing apache logs? [closed]

I can use log analyzers, but often I need to parse recent web logs to see what's happening at the moment. I sometimes do things like to figure out top 10 ips that request a certain file cat foo.log ...
2
votes
1answer
629 views

How does one simulate the old unix grep -S strict functionality in linux

I am grepping the output of a command and I wish to only return specific, strict results. I remember some iteration of grep had a strict option -s/--strict. For example, grep -s bytes would only ...
32
votes
6answers
32k views

Recursive text search with grep and file patterns

Given this example folder structure: /folder1/file1.txt /folder1/file2.djd /folder2/file3.txt /folder2/file2.fha How do I do a recursive text search on all *.txt files with grep from "/"? ("grep -...
7
votes
6answers
15k views

How to Find a file in FreeBSD

I'm trying to locate all copies of example.filename on my FreeBSD server. What's the best / easiest / most efficient way to do this?