Uniq

The uniq command outputs a file with adjacent identical lines removed. It does not remove non-adjacent duplicate lines. For example:

[email protected]:~> cat fish angelfish bream bream cod dogfish cod [email protected]:~> uniq fish angelfish bream cod dogfish cod

The uniq command can skip a certain number of fields or characters before starting its check for uniqueness. For example:

[email protected]:~> cat numberedfish

1 angelfish

2 bream

3 bream

4 cod

5 dogfish

6 cod [email protected]:~> uniq -f1 numberedfish

1 angelfish

2 bream

4 cod

5 dogfish

6 cod

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?

0 0

Post a comment