LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-03-2013, 03:22 PM   #1
sec_tech
LQ Newbie
 
Registered: Feb 2013
Posts: 5

Rep: Reputation: Disabled
AWK Print order


Is there anyway to force the print order of these three fields im extracting?
Code:
awk '/AP/{sub(/:80/, "", $4);printf "%s\t", $4} /User-Agent/{sub(/^[^:][^:]*:/,"");printf "%s\t", $0}/Host/{sub(/^[^:][^:]*:/,"");sub(/\.80/,"", $4);print}'
Let me clarify what is going on.
When IE makes a request it has User-Agent and Host in this order
Code:
T 12.237.222.221:57578 -> 70.37.131.11:80 [AP]
GET /c.gif?clid=3A8ACC9C01566FAB3DA8C8E105566FE0%26TUID%3D1&rid=CDA92F497C2347BEBCAD28088CA12CB7&cts=1362349841890&evt=unload HTTP/1.1.
Accept: image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5.
Referer: http://photos.msn.com/browse/places.
Accept-Language: en-US.
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0).
Accept-Encoding: gzip, deflate.
Host: udc.msn.com.
DNT: 1.
Connection: Keep-Alive.
Cookie:
When Chrome/Android/Iphone/ etc. Make a request it has User-Agent and Host in these locations:
Code:
T 12.237.222.221:57991 -> 4.59.125.171:80 [AP]
GET /linuxsquestions.org/217.html HTTP/1.1.
Host: www.unix.com.
Connection: keep-alive.
Cache-Control: max-age=0.
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22.
Referer: http://www.yahoo.com/advertisement.php?url=http://www.unix.com/showthread.php?t=217117.
Accept-Encoding: gzip,deflate,sdch.
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6.
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3.
Cookie:
Im REALLY hoping there is a way to force AWK to always print in order I need?

Last edited by sec_tech; 03-03-2013 at 05:05 PM. Reason: updated with more info.
 
Old 03-03-2013, 06:23 PM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,518

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
As the order changes you would need to store the data required in variables and then print in the order you wish after the file has been parsed.
 
1 members found this post helpful.
Old 03-03-2013, 06:50 PM   #3
sec_tech
LQ Newbie
 
Registered: Feb 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
As the order changes you would need to store the data required in variables and then print in the order you wish after the file has been parsed.
Can I do that with live streaming data being pumped into awk then sent to a file?
 
Old 03-03-2013, 09:26 PM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,518

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
Your streaming data to different browsers and a single awk at the same time?
 
  


Reply

Tags
awk


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
awk's asort sort order according to locale BerzinTehvs Linux - Software 4 08-03-2010 02:01 PM
how do i get ubuntu to print in reverse order baronobeefdip Linux - Hardware 4 05-09-2010 01:34 AM
CUPS - print pages in reverse order satinet Slackware 10 02-15-2010 01:38 PM
[SOLVED] Can I set the cups output order to always print in reverse order Thane Ubuntu 2 12-06-2009 06:57 AM
How to Configure Printer to Print in Order tom221 Linux - Networking 0 03-09-2005 02:36 PM


All times are GMT -5. The time now is 01:42 PM.

Main Menu
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