-   Programming (
-   -   awk run script on field before output (

Geneset 08-25-2008 06:37 PM

awk run script on field before output
hi guys,
quick question

i have an input that is ipaddress: port ipaddress: port TCP/UDP
can i take the ip's and "host ip" them on output?

I'm looking at something like

awk -F" |:" '{ print 'host $1'":"$2, 'host $3'":"$4,$5}' or something along those lines that will do in line substitution of these values for their hostnames

(replace "host ip" with "host ip | cut -d' ' -f5", but thats not as tidy in the above :D )

Thanks guys

Mr. C. 08-25-2008 09:36 PM

I think I understand that you saying you have something like: TCP

and you want them to be:

hostname1:1000 hostname2:2000

If so, here you go:

perl -F'/[:\s]/' -nae '@names = map { qx/dig -x $_ +noall +answer +short/ } @F[0,2]; chomp @names; print "host $names[0] : $F[1] host $names[1] : $F[3] $F[4]\n";'
Provide your input file as the last argument, or send it through a pipe. Adjust the print to your needs.

ghostdog74 08-25-2008 11:55 PM


awk 'BEGIN{}
 cmd = "dig -x "src[1]" +noall +answer +short"
 cmd | getline h
 cmd = "dig -x "dest[1]" +noall +answer +short"
 cmd | getline d
 print "host: "h":"src[2]" host: "d":"dest[2]
' file

Geneset 08-26-2008 05:59 AM

And thats why i keep coming back here, thanks guys

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