I can’t seem to identify where the syntax error is ..I’ve tried to these 2 statements but nothing gets written to the ‘BlockedIPs’ file. Can someone please help? Thanks!
awk '/ (TCP|UDP) / { split($5, addr, /:/); cmd = "/Users/user1/Scripts/geoiplookup " addr[1] | awk '{print $4, $5, $6}'; cmd | getline rslt; close(cmd); print $1, $2, $3, rslt }' < "$IP_PARSED" >> "$BlockedIPs"
awk '/ (TCP|UDP) / { split($5, addr, /:/); cmd = "/Users/user1/Scripts/geoiplookup " addr[1] " | awk '{print $4, $5, $6}'" ; cmd | getline rslt; close(cmd); print $1, $2, $3, rslt }' < "$IP_PARSED" >> "$BlockedIPs"
Your problem is primarily with quoting and stems from the fact that you’re trying to call AWK from within an AWK one-liner. It’s certainly possible, but getting the quoting right would be very tricky.
It would be much better if you retrieved the complete output of
geoiplookupinto a variable then did asplit()to get just the data you need. Something like: