uniq Command Purpose Deletes repeated lines in a file. Syntax uniq [ -c | -d | -u ] [ -f Fields ] [ -s Characters ] [ -Fields ] [ +Characters ] [ InFile [ OutFile ] ] Description The uniq command reads either standard input or the InFile parameter. The command first compares adjacent lines, then re- moves the second and succeeding duplications of a line. Dupli- cated lines must be adjacent. (Before issuing the uniq command, use the sort command to make all duplicate lines adjacent.) Fi- nally, the uniq command writes the resultant unique lines either to standard output or to the file specified by the OutFile param- eter. The InFile and OutFile parameters must specify different files. The uniq command compares entire lines by default. If the -f Fields or -Fields flag is specified, the uniq command ignores the number of fields specified by the Fields variable. A field is a string of characters separated from other character strings by one or more characters. If the -s Characters or -Characters flag is specified, the uniq command ignores the number of characters specified by the Characters variable. Values specified for the Fields and Characters variables must be positive decimal integers. The current National Language environment determines the characters used by the -f flag and it also determines how the -s flag interprets bytes as a character. The uniq command exits with a value of 0 if successful. Other- wise, it exits with a value greater than 0. Flags -c Precedes each output line with a count of the number of times each line appears in the file. This flag supersedes -d and -u. -d Displays only the repeated lines. -f Fields Ignores the number of fields specified by the Fields variable. This flag is equivalent to the -Fields flag. -u Displays only the unrepeated lines. -s Characters Ignores the number of characters specified by the Characters variable. If both the -f and -s flags are specified, the uniq command ignores the number of characters specified by the -s Characters flag starting in the field following the fields specified by the -f Fields flag. This flag is equivalent to the +Characters flag. -Fields Ignores the number of fields specified by the Fields var- iable. This flag is equivalent to the -f Fields flag. +Characters Ignores the number of characters specified by the Characters variable. If both the -Fields and +Characters flags are specified, the uniq command ignores the number of characters specified by the +Characters flag starting in the field following the fields specified by the -Fields flag. This flag is equivalent to the -s Characters flag. Exit Status This command returns the following exit values: 0 The command ran successfully. >0 An error occurred. Examples To delete repeated lines in a file named fruit and save it to a file named newfruit, enter: uniq fruit newfruit If the fruit file contains the following lines: apples apples peaches pears bananas cherries cherries then the newfruit file will contain the following lines after you run the uniq command: apples peaches pears bananas cherries Implementation Specifics This command is part of Base Operating System (BOS) Runtime. Files /usr/bin/uniq Contains the uniq command. Related Information The comm command, sort command.