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
uniq
You can do this with just grep and sort
grep
sort
DATAFILE=file.dat for match in $(grep -P '(!\w+!)' -o "$DATAFILE" | sort -u); do grep -m1 "$match" "$DATAFILE"; done
Outputs:
foo!bar!baz !baz!quix