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

learn more… | top users | synonyms

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 ...
41
votes
12answers
49k views

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

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

how to find out mac addresses of all machines on network

Is there some easy way to find out mac address of all machines on my network rather than doing an SSH into each and ifconfig | grep HWaddr if there are 300 machines on network I really need some easy ...
33
votes
5answers
5k views

How to prevent “ps” reporting its own process?

$ ps | grep django 28006 ttys004 0:01.12 /usr/bin/python bin/django celeryd --beat 51393 ttys005 0:01.45 /usr/bin/python bin/django celeryd -l INFO 51472 ttys005 0:01.29 /usr/bin/python ...
7
votes
9answers
4k 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 ...
12
votes
5answers
2k views

Grepping through .gz log files

Does there exist a magical shell piping which would allow easily to grep through bunch of .gz log files without needing to extract them somewhere? .gz files are Apache logs, result of log rotation. ...
23
votes
5answers
23k 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 ...
11
votes
2answers
9k 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 ...
10
votes
4answers
11k 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? ...
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!
8
votes
6answers
5k 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 - ...
5
votes
2answers
4k views

How can I handle spaces in file names when using xargs on find results?

One of my common practices is to perform greps on all files of a certain type, e.g., find all the HTML files that have the word "rumpus" in them. To do it, I use find /path/to -name "*.html" | xargs ...
3
votes
1answer
139 views

Need help grepping postfix log

I'm trying to search for an unknown string (Message ID) in a log based on a known string (recipient address), and then grep the unknown string to output the entire relevant log information. I'm able ...
0
votes
4answers
2k views

solaris + grep syntax in solaris

my target is to match Exactly the string snmpmanager from hosts file on solaris & linux the following command work on Linux (red-hat 5.1) but not for SunOS , please advice how to fit the syntax ...
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.
4
votes
3answers
3k views

grep or sed to find a integer value above a given amount?

This is in reference to another question: How do I use robocopy to list all files over a certain size recursively? I would like to parse output of a command (or cat a log file) and find a string ...
1
vote
2answers
4k views

How to grep httpd error_log within a time range?

How can I grep only lines from a huge (120GB) httpd error_log based on a time range, say: from 2011-11-15 11:30 pm to 2011-11-16 01:30 am Thanks!
0
votes
2answers
378 views

GREP find and use SED to replace string on all files

One of our old hosted Joomla sites suffered a JavaScript injection, and im going through cleaning it up. The following code was inserted into every .php or .js file: <? #0c0896# echo " <script ...
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 ...