I have a file containing patterns and messages separated by ":"
pattern1:First pattern
pattern12:Second pattern
pat1:Short pattern
pat12:Short pattern 2
If i run like this:
awk -F: '$1~/pat1/ {print $2}' file
it filters perfectly and gives output:
Short pattern
Short pattern 2
But actually I want to get messages of patterns which matching my provided string. Lets say i have a string example string with pattern12 substring inside
i would expect to get:
First pattern
Second pattern
because two patterns in the file matching my string. Unfortunately nor
awk -F: '$1~/example string with pattern12 substring inside/ {print $2}' file
neither
awk -F: '"example string with pattern12 substring inside"~/$1/ {print $2}' file
works for me.
Is there a way to achieve this with these simple and beautiful filters without moving check inside awk program body?
Thanks
Aucun commentaire:
Enregistrer un commentaire