LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-24-2009, 01:04 PM   #1
int0x80
Member
 
Registered: Sep 2002
Location: Cincinnati
Distribution: Debian GNU/Linux
Posts: 310

Rep: Reputation: 31
Question Simple (?) awk, two delimiters


I am trying to compile a list of IP addresses, timestamps, and useragents to my site. My log format is as follows:

Code:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined

Example:
216.54.147.14 - - [24/Feb/2009:08:53:50 -0500] "GET / HTTP/1.1" 200 56 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) Gecko/2009020911 Ubuntu/8.04 (hardy) Firefox/3.0.6"
I am able to pull items out separately, but cannot figure out how to do this more efficiently.

awk '{print $1, $4, $5}' gets me the IP address and timestamp.
awk -F\" '{print $6}' gets me the full useragent.

Is there a way to combine the two into one awk command? Or is there a fast/easy way to run the two awks separately and correlate the two lists?
 
Old 02-24-2009, 02:41 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
I have written numerous Perl scripts to parse these files, and have not yet found a one-line (or even a small number of lines) way of splitting the fields cleanly (too many delimiters used). I cannot see how such a format could have been adopted as any kind of standard.
Here's hoping someone comes forward with a clean solution in some regex-supporting language.
--- rod.
 
Old 02-24-2009, 08:48 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by int0x80 View Post
Is there a way to combine the two into one awk command?
try reading the documentation. Here's a section on field separators.
 
Old 02-25-2009, 09:53 AM   #4
int0x80
Member
 
Registered: Sep 2002
Location: Cincinnati
Distribution: Debian GNU/Linux
Posts: 310

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by ghostdog74 View Post
try reading the documentation. Here's a section on field separators.
Perhaps I am approaching this in the wrong manner. My thought is to print the first fields (IP, timestamp) then switch the FS and print the remaining field (useragent). I don't see anything discussing switching the FS inline, however.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple awk script question adam_blackice Programming 9 09-03-2007 03:23 PM
simple awk question getline coldy78 Programming 3 04-21-2007 12:39 AM
simple awk question mr_scary Linux - General 3 02-23-2007 07:37 PM
Simple question about sed or awk setianusa Programming 2 09-16-2005 04:57 PM
awk - simple 'for' loop doing my nut... davee Programming 2 06-30-2004 09:54 AM


All times are GMT -5. The time now is 06:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration