linux - Bash Script Awk Condition -


i have problem code.. can't figure out have write condition cut file awk.

i=0     while [ $i -lt 10 ]; #da 1 9, ap1..ap9            case $i in         1) rx="54:75:d0:3f:1e:f0";;         2) rx="54:75:d0:3f:4d:00";;         3) rx="54:75:d0:3f:51:50";;         4) rx="54:75:d0:3f:53:60";;         5) rx="54:75:d0:3f:56:10";;         6) rx="54:75:d0:3f:56:e0";;         7) rx="54:75:d0:3f:5a:b0";;         8) rx="54:75:d0:3f:5f:90";;         9) rx="d0:d0:fd:68:bc:70";;         *) echo "numero invalido!";;       esac       echo "rx = $rx" #check        awk -f, '$2 =="$rx" { print $0 }' file1 > file2[$i] #this line!   i=$(( $i + 1 ))   done 

the command echo prints correctly when use same "$rx" condition in awk doesn't work (it prints blank page). file1 :

1417164082794,54:75:d0:3f:53:60,54:75:d0:3f:1e:f0,-75,2400,6 1417164082794,54:75:d0:3f:56:10,54:75:d0:3f:1e:f0,-93,2400,4 1417164082794,54:75:d0:3f:56:e0,54:75:d0:3f:1e:f0,-89,2400,4 1417164082794,54:75:d0:3f:5a:b0,54:75:d0:3f:1e:f0,-80,2400,4 1417164082794,54:75:d0:3f:53:60,54:75:d0:3f:1e:f0,-89,5000,2

could tell me right expression "awk -f ..."

thank much!

@ricky - time write loop in shell manipulate text have wrong approach. it's not shell created - it's awk created , shell created invoke commands awk.

just use single awk command , instead of reading file 10 times , switching on variables every line of file, once, this:

begin {     split(file2s,f2s)     split("54:75:d0:3f:1e:f0\            54:75:d0:3f:4d:00\            54:75:d0:3f:51:50\            54:75:d0:3f:53:60\            54:75:d0:3f:56:10\            54:75:d0:3f:56:e0\            54:75:d0:3f:5a:b0\            54:75:d0:3f:5f:90\            d0:d0:fd:68:bc:70", rxs)     (i in rxs) {         rx2file2s[rxs[i]] = f2s[i]     } } {     if ($2 in rx2file2s) {         print > rx2file2s[$2]     }     else {         print nr, $2, "numero invalido!" | "cat>&2"     } } 

which you'd invoke awk -v file2s="${file2[@]}" -f script.awk file1

i "something like" because didn't provide sample input (file1 contents) or expected output (file2* values , contents) couldn't test close need if not right.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -