10

Error passing parameter in "sub" command in awk

view full story
linux-howto

http://www.unix.com – I have to replace the pattern found in one file in another file with null/empty "" if found on the fields 3 or 4 ONLY Code: File 1 ==== 10604747|Mxdef|9999|9999|9999|2012-03-04 00:00:59 10604747|Mcdef|8888|9999|8888|2012-03-04 00:00:59 . . . File 2 ==== 9999 8888 . . .   Expected output:   File 1 ==== 10604747|Mxdef|||9999|2012-03-04 00:00:59 10604747|Mcdef|||8888|2012-03-04 00:00:59 I tried something like while read i do awk -v FS="|" -v OFS="|" 'BEGIN { split("3|4", F); } { for(N in F) sub(/'$i'/, "", $(F[N])) } 1' Fil (HowTos)