Reputation: 406
I want to use awk to search for pattern in multiple files but exclude some patterns from file
This is the code I have tried
BEGIN { print "Begin Processing of various Records"}
/Type.*ABC/ {a=1} /999/{a=0; if (a==1) print a;}
END { print "Process Complete" }
Examples:
This is the file example
Resources:
CODE:
Type: "ABC::DEF::AVC"
Type: "ABC::DEF::999"
Type: "ABC::DEF::ZZZ"
Now suppose I have file excludes with content
999
888
ZZZ
Now, I want to display all lines with match first pattern but excludes if any pattern from excludes is found.
Upvotes: 3
Views: 3597
Reputation:
if your data in 'd' file, try gnu awk:
awk '/Type.*ABC/ && $0 !~ /999|888|ZZZ/' d
Upvotes: 1
Reputation: 203995
Is this what you're trying to do?
$ awk -F'[:"]' 'NR==FNR{a[$0];next} /Type.*ABC/ && !($(NF-1) in a)' excludes file
Type: "ABC::DEF::AVC"
Upvotes: 3