LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   AWK Print order (http://www.linuxquestions.org/questions/linux-newbie-8/awk-print-order-4175452541/)

sec_tech 03-03-2013 04:22 PM

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?

grail 03-03-2013 07:23 PM

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.

sec_tech 03-03-2013 07:50 PM

Quote:

Originally Posted by grail (Post 4903929)
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?

grail 03-03-2013 10:26 PM

Your streaming data to different browsers and a single awk at the same time?


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