8.1 Working With Files
Syntax
uniq [options] [+|-n] file [file.new]
Common Options
-d one copy of only the repeated lines
-u select only the lines not repeated
+n ignore the first n characters
-s n same as above (SVR4 only)
-n skip the first n fields, including any blanks (<space> & <tab>)
-f fields same as above (SVR4 only)
Examples
Consider the following file and example, in which uniq removes the 4th line from file and places the result in a file called file.new.
{unix prompt 1} cat file
1 2 3 6
4 5 3 6
7 8 9 0
7 8 9 0
{unix prompt 2} uniq file file.new
{unix prompt 3} cat file.new
1 2 3 6
4 5 3 6
7 8 9 0
Below, the -n option of the uniq command is used to skip the first 2 fields in file, and filter out lines which are duplicates from the 3rd field onward.
{unix prompt 4} uniq -2 file
1 2 3 6
7 8 9 0