shell command using awk fields inside awk
Hi,
I am not an awk specialist. In short I want to write a script (bash/awk) which reads the squid access output file, sorts unique it using only the destination "hosts" and then prints out: how many times destination host was requested, % of the requests, destination host name, destination host IP. This all without writing in tmp files. Say the input is: Code:
1196377810.470 405 10.4.1.119 TCP_MISS/200 410 POST http://shttp.msg.yahoo.com/notify/ - DEFAULT_PARENT/localhost text/plain Code:
1 25% shttp.msg.yahoo.com Code:
#! /bin/bash I mean I should put "somewhere" in the last line of the code (inside the awk) the command: Code:
host -t a $2 | grep address | awk '{print $4}' Conceptually something like: Code:
awk '{ABC=`host -t a $2 | grep address | awk '{print $4}'`; {print $1, "\t", ($1*100)/"'$WCTOT'" "%", "\t", $2, $ABC}' > $FILEOUT Do you know a way to solve this problem? Thanks |
If Perl is acceptable (the output is not sorted, you want to sort by what?):
Code:
perl -MSocket -lane' Code:
perl -MSocket -lane' |
Hi,
thanks for your code.
any idea? |
I understand, try this:
Code:
perl -MSocket -lne' I suppose your code is fast because you don't do the host resolution. If this still errors, could you attach a biggest sample of your log? |
Using awk to do this is really ugly, and FAR more expensive. You'll be calling host, and having to parse the output from within awk, but that's not easy, as the output
The perl script is more efficient, and has a minor error - don't toss the baby out with the bathwater. What is the input line where the script is exiting? If you don't understand, or want the perl scripts above, try just this last script to do your hostname -> IP translation. Add it to the end of your pipeline: Code:
... your stuff here ... | |
With AWK and sort (not elegant, as already stated):
Code:
awk -F'http://' '{ |
Thats a total of 10 processes + 1 for each host call, and 10 passes through the data, including 3 sorts on the data. Very nasty.
Radoulov - nice work! |
All times are GMT -5. The time now is 09:33 AM. |