cheatsheet: "Using awk, uniq, and grep to filter files
For example for a file web.log with entries that look like
216.103.110.18 - - [27/Mar/2002:03:59:14 -0500] 'GET /people/index.htm HTTP/1.1'
304 - 'http://www.plambeck.org.com/index.htm' 'Mozilla/4.0 (compatible; MSIE 6.0; Win
dows 98; Q312461)'
Use the command
cat web.log awk -F- '{print $1}'
to display the first word on each line that comes before the - sign (ie, the IP address in the example above).
Then use some combination of use 'uniq' and 'sort' to achieve your goal; for example
cat web.log awk -F- '{print $1}' sort uniq -c
to print out number of log entries per IP number.
To get grep to print out lines that don't match a pattern, use the -v option:
cat web.log grep -v 216 "
Monday, June 25, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment