UNIQ(1)                    POSIX Programmer's Manual                   UNIQ(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       uniq -- report or filter out repeated lines in a file

SSYYNNOOPPSSIISS
       uniq [[-c|-d|-u]] [[-f _f_i_e_l_d_s]] [[-s _c_h_a_r]] [[_i_n_p_u_t___f_i_l_e [[_o_u_t_p_u_t___f_i_l_e]]]]

DDEESSCCRRIIPPTTIIOONN
       The _u_n_i_q 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.  The trailing <newline> of each line in the input shall be
       ignored when doing comparisons.

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

OOPPTTIIOONNSS
       The _u_n_i_q utility shall conform to the Base Definitions volume of
       POSIX.1-2008, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s, except that ''++''
       may be recognized as an option delimiter as well as ''--''.

       The following options shall be supported:

       --cc        Precede each output line with a count of the number of times
                 the line occurred in the input.

       --dd        Suppress the writing of lines that are not repeated in the
                 input.

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

                     [[[[::bbllaannkk::]]]]**[[^^[[::bbllaannkk::]]]]**

                 If the _f_i_e_l_d_s option-argument specifies more fields than
                 appear on an input line, a null string shall be used for
                 comparison.

       --ss _c_h_a_r_s  Ignore the first _c_h_a_r_s characters when doing comparisons,
                 where _c_h_a_r_s shall be a positive decimal integer. If specified
                 in conjunction with the --ff option, the first _c_h_a_r_s characters
                 after the first _f_i_e_l_d_s fields shall be ignored. If the _c_h_a_r_s
                 option-argument specifies more characters than remain on an
                 input line, a null string shall be used for comparison.

       --uu        Suppress the writing of lines that are repeated in the input.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _i_n_p_u_t___f_i_l_e
                 A pathname of the input file. If the _i_n_p_u_t___f_i_l_e operand is
                 not specified, or if the _i_n_p_u_t___f_i_l_e is ''--'', the standard
                 input shall be used.

       _o_u_t_p_u_t___f_i_l_e
                 A pathname of the output file. If the _o_u_t_p_u_t___f_i_l_e operand is
                 not specified, the standard output shall be used. The results
                 are unspecified if the file named by _o_u_t_p_u_t___f_i_l_e is the file
                 named by _i_n_p_u_t___f_i_l_e.

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

IINNPPUUTT FFIILLEESS
       The input file shall be a text file.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _u_n_i_q:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2008, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_O_L_L_A_T_E
                 Determine the locale for ordering rules.

       _L_C___C_T_Y_P_E  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 <blank> in the
                 current locale.

       _L_C___M_E_S_S_A_G_E_S
                 Determine the locale that should be used to affect the format
                 and contents of diagnostic messages written to standard
                 error.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       The standard output shall be used if no _o_u_t_p_u_t___f_i_l_e operand is
       specified, and shall be used if the _o_u_t_p_u_t___f_i_l_e operand is ''--'' and the
       implementation treats the ''--'' as meaning standard output. Otherwise,
       the standard output shall not be used.  See the OUTPUT FILES section.

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

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

           ""%%dd %%ss"",, <<_n_u_m_b_e_r _o_f _d_u_p_l_i_c_a_t_e_s>, <_l_i_n_e>

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

           ""%%ss"",, <<_l_i_n_e>

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       The following exit values shall be returned:

        0    The utility executed successfully.

       >0    An error occurred.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       Default.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The _s_o_r_t utility can be used to cause repeated lines to be adjacent in
       the input file.

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

           ##0011 ffoooo00 bbaarr00 ffoooo11 bbaarr11
           ##0022 bbaarr00 ffoooo11 bbaarr11 ffoooo11
           ##0033 ffoooo00 bbaarr00 ffoooo11 bbaarr11
           ##0044
           ##0055 ffoooo00 bbaarr00 ffoooo11 bbaarr11
           ##0066 ffoooo00 bbaarr00 ffoooo11 bbaarr11
           ##0077 bbaarr00 ffoooo11 bbaarr11 ffoooo00

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

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

               uunniiqq --cc --ff 11 uunniiqq__00II..tt
                   11 ##0011 ffoooo00 bbaarr00 ffoooo11 bbaarr11
                   11 ##0022 bbaarr00 ffoooo11 bbaarr11 ffoooo11
                   11 ##0033 ffoooo00 bbaarr00 ffoooo11 bbaarr11
                   11 ##0044
                   22 ##0055 ffoooo00 bbaarr00 ffoooo11 bbaarr11
                   11 ##0077 bbaarr00 ffoooo11 bbaarr11 ffoooo00

           The number ''22'', prefixing the fifth line of output, signifies that
           the _u_n_i_q utility detected a pair of repeated lines. Given the input
           data, this can only be true when _u_n_i_q is run using the --ff 11 option
           (which shall cause _u_n_i_q to ignore the first field on each input
           line).

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

               uunniiqq --dd --ff 11 uunniiqq__00II..tt
               ##0055 ffoooo00 bbaarr00 ffoooo11 bbaarr11

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

               uunniiqq --uu --ff 11 uunniiqq__00II..tt
               ##0011 ffoooo00 bbaarr00 ffoooo11 bbaarr11
               ##0022 bbaarr00 ffoooo11 bbaarr11 ffoooo11
               ##0033 ffoooo00 bbaarr00 ffoooo11 bbaarr11
               ##0044
               ##0077 bbaarr00 ffoooo11 bbaarr11 ffoooo00

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

               uunniiqq --dd --ss 22 uunniiqq__00II..tt

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

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

       Earlier versions of this standard allowed the --_n_u_m_b_e_r and ++_n_u_m_b_e_r
       options. These options are no longer specified by POSIX.1-2008 but may
       be present in some implementations.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _c_o_m_m, _s_o_r_t

       The Base Definitions volume of POSIX.1-2008, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                              UNIQ(1)
