uniq
is a tool that enables once to filter lines in a file such that only unique lines are shown. uniq
has some support to specify when two lines a
Not using uniq
but using gnu-awk you can get the results you want:
awk -v re='![[:alnum:]]+!' 'match($0, re, a) && !(a[0] in p) {p[a[0]]; print}' file
foo!bar!baz
!baz!quix
-v re=...
match
function matches regex for each line and returns matched text in [a]
match
succeeds we store matched text in an associative array p
and printuniq
function with regex
support