Parsing out access.log with awk and grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing out access.log with awk and grep
# 1  
Old 04-25-2011
Parsing out access.log with awk and grep

In part of my script I use awk to pull out the urls.

awk '{print $8}' then I take them and send them to grep.`

Some of them are straight .com/ or .org or whatever (address bar entries), while others are locations of images, js, etc.

I'm trying to only pull any line that ends with .com/ .org/ .net/ and regexs are truly not my strong suit.

Grep 'ing this is not working:
(.com/|.org/|.net/)$

Any takers?
# 2  
Old 04-25-2011
You need egrep to do that.

Code:
 egrep "\.(com|org|net)/?$"

# 3  
Old 04-25-2011
You need to use extended-regex, and you should escape dot, the dot in your regex will match any character since it is not escaped.
Code:
grep -E '(\.com/|\.org/|\.net/)$'

# 4  
Old 04-25-2011
Try:
Code:
awk '/\.com/  || /\.org/ || /\.net/ {print $8}'

If this isn't what you're looking for, post some lines of the log file and the desired output.
# 5  
Old 04-25-2011
# 6  
Old 04-25-2011
I suggest you use Perl to parse access logs, it's more powerful and easier to handle complicated cases with it.
I often use a single Regex in Perl to extract all the desired fields from the log file.
# 7  
Old 04-25-2011
Have you tried this?
Code:
awk '/\.com/  || /\.org/ || /\.net/ {print $8}' logfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed / awk / grep to extract information from log

Hi all, I have a query that runs that outputs data in the following format - 01/09/12 11:43:40,ADMIN,4,77,Application Group Load: Name(TESTED) LoadId(5137-1-0-1XX-15343-15343) File(/dir/dir/File.T03.CI2.RYR.2012009.11433350806.ARD) InputSize(5344) OutputSize(1359) Rows(2) Time(1.9960)... (8 Replies)
Discussion started by: jeffs42885
8 Replies

2. Shell Programming and Scripting

awk script to find time difference between HTTP PUT and HTTP DELETE requests in access.log

Hi, I'm trying to write a script to determine the time gap between HTTP PUT and HTTP DELETE requests in the HTTP Servers access log. Normally client will do HTTP PUT to push content e.g. file_1.txt and 21 seconds later it will do HTTP DELETE, but sometimes the time varies causing some issues... (3 Replies)
Discussion started by: Juha
3 Replies

3. Shell Programming and Scripting

awk to grep log

hi expert, i Have log like : dn: EPC-Per=673,HYHGU objectClass: EPC-PerSubs ownerId: 0 groupId: 4001 shareTree: nodeName=HYHGU permissions: 15 EPC-Per: 673 dn:... (2 Replies)
Discussion started by: justbow
2 Replies

4. Shell Programming and Scripting

Issue with awk script parsing log file

Hello All, I am trying to parse a log file and i got this code from one of the good forum colleagues, However i realised later there is a problem with this awk script, being naive to awk world wanted to see if you guys can help me out. AWK script: awk '$1 ~ "^WRITER_" {p=1;next}... (18 Replies)
Discussion started by: Ariean
18 Replies

5. Shell Programming and Scripting

Need help with awk and access log

when i run this command: tail -200 /var/log/httpd/access_log | awk -F'' '{sub(/:*$/,"",$2);print $2}' i get: 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56 13/Aug/2012:20:56... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Shell Programming and Scripting

Access log field - using awk to pull date/time

hey guys. the following line is a line taken from apache's access_log 10.10.10.10 - jdoe "GET /images/down.gif HTTP/1.1" 304 I'm concerned about the field that has the date and time in it. if assuming the delimiter in the file is a space, then the fourth field will always have the date... (5 Replies)
Discussion started by: SkySmart
5 Replies

7. UNIX for Dummies Questions & Answers

awk/grep or parsing in python code

Hello, I am writing a python code. The output of the python code needs a little bit of parsing. From the output of python code, which has a lot of redundant data, I need to cut only those words or numbers which end with &. for example: if the output is-- "This is an example of tgbn123& what i... (0 Replies)
Discussion started by: Screech_you
0 Replies

8. Shell Programming and Scripting

Router ping log extract data from it Awk/Sed/grep

Hi, I am new to this world.. Using expect i loging to router and checking ping response to my links. I need to genarate report using this output and that report contains only three file link name, packet loss, latency. my output of script is like below: -bash-3.00$ monmw/mwbkp... (2 Replies)
Discussion started by: jkmistry
2 Replies

9. UNIX for Advanced & Expert Users

WEB Server Log File Analysis using awk/sed/grep

I'm trying to find a way to show large page sizes (page size in K) from multiple web server log files. Essentially I want to show only rows from a file where a specific column is larger than some value. Has anyone ever done this type of log analysis? If so, a snippet of code would be very... (2 Replies)
Discussion started by: mike_cataldo@ad
2 Replies

10. UNIX for Dummies Questions & Answers

Constantly updating log files (tail -f? grep? awk?)

I have a log file which is continuously added to, called log.file. I'd like to monitor this file, and when certain lines are found, update some totals in another file. I've played around with tail -f, grep, and awk, but can't seem to hit the right note, so to speak. The lines I'm... (0 Replies)
Discussion started by: nortonloaf
0 Replies
Login or Register to Ask a Question