2021-03-30

awk pattern matching one file to another then save the difference in new file

$ cat File1
781789
989778
898989

$ cat File2
AA^ABB^ACC^A781789^B781782^AEE^AFF^A781789^B781782AA^ABB^ACC^A7817891^B7817821^AEE^AFF^A7817891^B781782AA^ABB^ACC^A781789^B898989^AEE^AFF^A781789^B898989^B898923
  • Field Separator: "^A" or "\x01"
  • Record Separator: "^B" or "\x02"

I would like to create a resultant file "File3" where records from "File1" DOES NOT match any of the records for Column number 4 and 7 in "File2". If the record matches then DO NOT consider.

Expected output:

$ cat File3
AA^ABB^ACC^A7817891^B7817821^AEE^AFF^A7817891^B781782

Tried with the below awk code, where I am able to parse "File2" with field separators, but not able to match records from "File1" to "File2".

awk 'BEGIN { FS="\x01"} NR==FNR{A[$4]~/$0/;next}{print A[$0]} File1 File2 > File3'

awk 'BEGIN { FS="\x01"} NR==FNR{A[$7]~/$0/;next}{print A[$0]} File1 File2 > File3'

Requesting help.



from Recent Questions - Stack Overflow https://ift.tt/3dlsi3w
https://ift.tt/eA8V8J

No comments:

Post a Comment