uniq requires its input to be sorted if you want it to work in this manner. From the man page: (emphasis mine)
DESCRIPTION: Filter adjacent matching lines
So you could put a sort
before the uniq
in the pipeline, but that is not necessary, you can simply use the -u
flag to sort
to only output unique lines from the sorted output:
egrep -oh '([A-Z]+)_([A-Z]+)_([A-Z]+)' -R /path | sort -u