LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 12:04 PM   #1
int0x80
Member
 
Registered: Sep 2002
Posts: 310

Rep: Reputation: Disabled
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, 01:41 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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, 07:48 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
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, 08:53 AM   #4
int0x80
Member
 
Registered: Sep 2002
Posts: 310

Original Poster
Rep: Reputation: Disabled
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



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 02:23 PM
simple awk question getline coldy78 Programming 3 04-20-2007 11:39 PM
simple awk question mr_scary Linux - General 3 02-23-2007 06:37 PM
Simple question about sed or awk setianusa Programming 2 09-16-2005 03:57 PM
awk - simple 'for' loop doing my nut... davee Programming 2 06-30-2004 08:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:40 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
Open Source Consulting | Domain Registration