The uniq command outputs a file with adjacent identical lines removed. It does not remove non-adjacent duplicate lines. For example:
The uniq command can skip a certain number of fields or characters before starting its check for uniqueness. For example:
[email protected]:~> cat numberedfish
6 cod [email protected]:~> uniq -f1 numberedfish
The -f1 option here tells the uniq command to skip the first field in the file when deciding whether the lines match. Because lines 2 and 3 were identical apart from the first field, line 3 has been dropped.
Was this article helpful?