Awk syntax error

I get this syntax error with my code - I tried putting quotes in different places, but no luck. Can someone help. Thank!

awk: non-terminated string  | grep Re... at source line 1
 context is
     >>>  <<< 
awk: giving up
 source line number 2
awk '/ (TCP|UDP) / { split($5, addr, /:/); 
cmd = "/bin/geoiplookup " addr[1] | grep 'Rev 1:' | sed 's/Rev 1: //g' " | awk -F', ' '{print $4",", $3",", $2}'; 
cmd | getline rslt; 
close(cmd); 
print $1, $2, $3, $4, $5, $6, rslt }' < "$IP_PARSED" >> "$BlockedIPs"
+3
source share
3 answers

I think we have been here before. Do not try to perform complex processing inside cmd. Use it to run an external command, and then do the processing inside the main AWK program.

awk '/ (TCP|UDP) / { split($5, addr, /:/); 
cmd = "/bin/geoiplookup " addr[1] ; 
while (cmd | getline rslt) {
    if (rslt ~ /Rev 1: /) {
        gsub(/Rev 1: /, "", rslt)
        split(rslt, r, ",")
    }
}
close(cmd); 
print $1, $2, $3, $4, $5, $6, r[4], r[3], r[2] }' < "$IP_PARSED" >> "$BlockedIPs"
+1
source

awk . awk . , awk script, awk script ( ) \ . , .

+2

. ; , . ,

$ echo 'hello'"'"'world'
hello'world
$ echo 'hello'\''world'
hello'world

: \' , .

$ echo 'hello\'world'
hello\'world
+1

All Articles