Man uniq linux команда

Man uniq linux команда

The uniq utility reads an input file comparing adjacent lines and writes one copy of each input line on the output. The second and succeeding copies of repeated adjacent input lines are not written.

Repeated lines in the input are not detected if they are not adjacent.

ksh93

The uniq built-in in ksh93 is associated with the /bin or /usr/bin path . It is invoked when uniq is executed without a pathname prefix and the pathname search finds a /bin/uniq or /usr/bin/uniq executable.

uniq reads an input, comparing adjacent lines, and writing one copy of each input line on the output. The second and succeeding copies of the repeated adjacent lines are not written.

If output_file is not specified, uniq writes to standard output. If input_file is not specified, or if input_file is — , uniq reads from standard input, and the start of the file is defined as the current offset.

OPTIONS


/usr/bin/uniq

The following options are supported by /usr/bin/uniq :

-c Precedes each output line with a count of the number of times the line occurred in the input.

-d Suppresses the writing of lines that are not repeated in the input.

-f fields Ignores the first fields fields on each input line when doing comparisons, where fields is a positive decimal integer. A field is the maximal string matched by the basic regular expression:

If fields specifies more fields than appear on an input line, a null string is used for comparison.

+ m Equivalent to -s chars with chars set to m .

— n Equivalent to -f fields with fields set to n .

-s chars Ignores the first chars characters when doing comparisons, where chars is a positive decimal integer. If specified in conjunction with the -f option, the first chars characters after the first fields fields is ignored. If chars specifies more characters than remain on an input line, a null string is used for comparison.

-u Suppresses the writing of lines that are repeated in the input.

ksh93

The following options are supported by the uniq built-in command is ksh93 :

-c
—count Outputs the number of times each line occurred along with the line.

-d
—repeated | duplicates Outputs only duplicate lines.

-D
—all-repeated [ = delimit ] Outputs all duplicate lines as a group with an empty line delimiter specified by delimit .

Specify delimit as one of the following:

none Do not delimit duplicate groups.

prepend Prepend an empty line before each group.

separate Separate each group with an empty line.

The value for delimit can be omitted. The default value is none .

-f
—skip-fields= fields Skips over fields number of fields before checking for uniqueness. A field is the minimal string matching the BRE [[: blank :]]*[^[: blank :]]* .

Читайте также:  What is mta in linux

-i
—ignore-case Ignore case in comparisons.

+ m Equivalent to the -s chars option, with chars set to m .

— n Equivalent to the -f fields option, with fields set to n .

-s
—skip-chars= chars Skips over chars number of characters before checking for uniqueness.

If specified with the -f option, the first chars after the first fields are ignored. If the chars specifies more characters than are on the line, an empty string is used for comparison.

-u
—uniq Outputs unique lines.

-w
—check-chars= chars Skips over any specified fields and characters, then compares chars number of characters.

OPERANDS

The following operands are supported:

input_file A path name of the input file. If input_file is not specified, or if the input_file is — , the standard input is used.

output_file A path name of the output file. If output_file is not specified, the standard output is used. The results are unspecified if the file named by output_file is the file named by input_file .

EXAMPLES

Example 1 Using the uniq Command

The following example lists the contents of the uniq.test file and outputs a copy of the repeated lines.

example% cat uniq.test This is a test. This is a test. TEST. Computer. TEST. TEST. Software. example% uniq -d uniq.test This is a test. TEST. example%

The next example outputs just those lines that are not repeated in the uniq.test file.

example% uniq -u uniq.test TEST. Computer. Software. example%

The last example outputs a report with each line preceded by a count of the number of times each line occurred in the file:

example% uniq -c uniq.test 2 This is a test. 1 TEST. 1 Computer. 2 TEST. 1 Software. example%

ENVIRONMENT VARIABLES

See environ (5) for descriptions of the following environment variables that affect the execution of uniq : LANG , LC_ALL , LC_CTYPE , LC_MESSAGES , and NLSPATH .

EXIT STATUS

The following exit values are returned:

ATTRIBUTES

See attributes (5) for descriptions of the following attributes:

/usr/bin/uniq

ATTRIBUTE TYPEATTRIBUTE VALUE
AvailabilitySUNWesu
CSI
Interface Stability
Standard

ksh93

ATTRIBUTE TYPEATTRIBUTE VALUE
AvailabilitySUNWcsu
Interface Stability

The ksh93 built-in binding to /bin and /usr/bin is Volatile. The built-in interfaces are Uncommitted.

SEE ALSO


Index

PostgresPro

Inferno Solutions

Источник

Man uniq linux команда

uniq [ -c|-d|-u ][ -f fields ][ -s char ][ input_file [ output_file ]]

DESCRIPTION

The uniq utility shall read an input file comparing adjacent lines, and write one copy of each input line on the output. The second and succeeding copies of repeated adjacent input lines shall not be written.

Repeated lines in the input shall not be detected if they are not adjacent.

OPTIONS

The uniq utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.

The following options shall be supported: -c Precede each output line with a count of the number of times the line occurred in the input. -d Suppress the writing of lines that are not repeated in the input. -f fields Ignore the first fields fields on each input line when doing comparisons, where fields is a positive decimal integer. A field is the maximal string matched by the basic regular expression:

If the fields option-argument specifies more fields than appear on an input line, a null string shall be used for comparison. -s chars Ignore the first chars characters when doing comparisons, where chars shall be a positive decimal integer. If specified in conjunction with the -f option, the first chars characters after the first fields fields shall be ignored. If the chars option-argument specifies more characters than remain on an input line, a null string shall be used for comparison. -u Suppress the writing of lines that are repeated in the input.

OPERANDS

The following operands shall be supported: input_file A pathname of the input file. If the input_file operand is not specified, or if the input_file is ‘-‘ , the standard input shall be used. output_file A pathname of the output file. If the output_file operand is not specified, the standard output shall be used. The results are unspecified if the file named by output_file is the file named by input_file .

STDIN

The standard input shall be used only if no input_file operand is specified or if input_file is ‘-‘ . See the INPUT FILES section.

INPUT FILES

The input file shall be a text file.

ENVIRONMENT VARIABLES

The following environment variables shall affect the execution of uniq : LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE

Determine the locale for ordering rules. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files) and which characters constitute a in the current locale. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES .

ASYNCHRONOUS EVENTS


STDOUT

The standard output shall be used only if no output_file operand is specified. See the OUTPUT FILES section.

STDERR

The standard error shall be used only for diagnostic messages.

OUTPUT FILES

If the -c option is specified, the output file shall be empty or each line shall be of the form:

"%d %s", number of duplicates>, line> 

otherwise, the output file shall be empty or each line shall be of the form:

EXTENDED DESCRIPTION


EXIT STATUS

The following exit values shall be returned: 0 The utility executed successfully. >0 An error occurred.

CONSEQUENCES OF ERRORS

The following sections are informative.

APPLICATION USAGE

The sort utility can be used to cause repeated lines to be adjacent in the input file.

EXAMPLES

The following input file data (but flushed left) was used for a test series on uniq :

#01 foo0 bar0 foo1 bar1 #02 bar0 foo1 bar1 foo1 #03 foo0 bar0 foo1 bar1 #04 #05 foo0 bar0 foo1 bar1 #06 foo0 bar0 foo1 bar1 #07 bar0 foo1 bar1 foo0 

What follows is a series of test invocations of the uniq utility that use a mixture of uniq options against the input file data. These tests verify the meaning of adjacent . The uniq utility views the input data as a sequence of strings delimited by ‘\n’ . Accordingly, for the fields th member of the sequence, uniq interprets unique or repeated adjacent lines strictly relative to the fields +1th member.

This first example tests the line counting option, comparing each line of the input file data starting from the second field:

uniq -c -f 1 uniq_0I.t 1 #01 foo0 bar0 foo1 bar1 1 #02 bar0 foo1 bar1 foo0 1 #03 foo0 bar0 foo1 bar1 1 #04 2 #05 foo0 bar0 foo1 bar1 1 #07 bar0 foo1 bar1 foo0 

The number ‘2’ , prefixing the fifth line of output, signifies that the uniq utility detected a pair of repeated lines. Given the input data, this can only be true when uniq is run using the -f 1 option (which shall cause uniq to ignore the first field on each input line).

The second example tests the option to suppress unique lines, comparing each line of the input file data starting from the second field:

uniq -d -f 1 uniq_0I.t #05 foo0 bar0 foo1 bar1 

This test suppresses repeated lines, comparing each line of the input file data starting from the second field:

uniq -u -f 1 uniq_0I.t #01 foo0 bar0 foo1 bar1 #02 bar0 foo1 bar1 foo1 #03 foo0 bar0 foo1 bar1 #04 #07 bar0 foo1 bar1 foo0 

This suppresses unique lines, comparing each line of the input file data starting from the third character:

In the last example, the uniq utility found no input matching the above criteria.

RATIONALE

Some historical implementations have limited lines to be 1080 bytes in length, which does not meet the implied limit.

Источник

Man uniq linux команда

Удаляет все кроме одной повторяющиеся строки из ВВОДА (или стандартного ввода) и печатает на ВЫВОД (или стандартный вывод).

Обязательные аргументы для длинных ключей обязательны и для коротких. -c , —count выводить число повторов в начале каждой строки -d , —repeated выводить только повторяющиеся строки -D , —all-repeated [= delimit-method ] печатать все повторяющиеся строки delimit-method= Разделение делается по пустым строкам. -f , —skip-fields = N не сравнивать первые N полей -i , —ignore-case игнорировать регистр при сравнении -s , —skip-chars = N не сравнивать первые N знаков -u , —unique выводить только неповторяющиеся строки -w , —check-chars = N сравнивать только первые N символов в строке —help показать справку и выйти —version показать информацию о версии и выйти

Полем считается последовательность пробельных знаков, за которой следуют непробельные знаки. Сначала пропускаются поля, потом знаки.

АВТОРЫ


СООБЩЕНИЕ ОБ ОШИБКАХ


АВТОРСКИЕ ПРАВА

Copyright (c) 2006 Free Software Foundation, Inc.
Это свободное программное обеспечение. Вы можете распространять его копии при соблюдении условий GNU General Public License . Не предоставляется НИКАКИХ ГАРАНТИЙ в установленных законом пределах.

СМ. ТАКЖЕ

Полная документация для uniq поддерживается в виде руководства в формате Texinfo. Если программы info и uniq установлены и настроены в системе, то по команде info uniq

вы получите доступ к более полному руководству.

Источник

Оцените статью
Adblock
detector