Files
oldlinux-files/Ref-docs/POSIX/susv3/utilities/uniq.html
2024-02-19 00:21:47 -05:00

356 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>uniq</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="uniq"></a> <a name="tag_04_158"></a><!-- uniq -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_04_158_01"></a>NAME</h4>
<blockquote>uniq - report or filter out repeated lines in a file</blockquote>
<h4><a name="tag_04_158_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>uniq</tt> <b>[</b><tt>-c|-d|-u</tt><b>][</b><tt>-f</tt> <i>fields</i><b>][</b><tt>-s</tt>
<i>char</i><b>][</b><i>input_file</i> <b>[</b><i>output_file</i><b>]]</b></code></p>
</blockquote>
<h4><a name="tag_04_158_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>uniq</i> 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.</p>
<p>Repeated lines in the input shall not be detected if they are not adjacent.</p>
</blockquote>
<h4><a name="tag_04_158_04"></a>OPTIONS</h4>
<blockquote>
<p>The <i>uniq</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
<p>The following options shall be supported:</p>
<dl compact>
<dt><b>-c</b></dt>
<dd>Precede each output line with a count of the number of times the line occurred in the input.</dd>
<dt><b>-d</b></dt>
<dd>Suppress the writing of lines that are not repeated in the input.</dd>
<dt><b>-f&nbsp;</b> <i>fields</i></dt>
<dd>Ignore the first <i>fields</i> fields on each input line when doing comparisons, where <i>fields</i> is a positive decimal
integer. A field is the maximal string matched by the basic regular expression:
<pre>
<tt>[[:blank:]]*[^[:blank:]]*
</tt>
</pre>
<p>If the <i>fields</i> option-argument specifies more fields than appear on an input line, a null string shall be used for
comparison.</p>
</dd>
<dt><b>-s&nbsp;</b> <i>chars</i></dt>
<dd>Ignore the first <i>chars</i> characters when doing comparisons, where <i>chars</i> shall be a positive decimal integer. If
specified in conjunction with the <b>-f</b> option, the first <i>chars</i> characters after the first <i>fields</i> fields shall be
ignored. If the <i>chars</i> option-argument specifies more characters than remain on an input line, a null string shall be used
for comparison.</dd>
<dt><b>-u</b></dt>
<dd>Suppress the writing of lines that are repeated in the input.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_158_05"></a>OPERANDS</h4>
<blockquote>
<p>The following operands shall be supported:</p>
<dl compact>
<dt><i>input_file</i></dt>
<dd>A pathname of the input file. If the <i>input_file</i> operand is not specified, or if the <i>input_file</i> is <tt>'-'</tt> ,
the standard input shall be used.</dd>
<dt><i>output_file</i></dt>
<dd>A pathname of the output file. If the <i>output_file</i> operand is not specified, the standard output shall be used. The
results are unspecified if the file named by <i>output_file</i> is the file named by <i>input_file</i>.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_158_06"></a>STDIN</h4>
<blockquote>
<p>The standard input shall be used only if no <i>input_file</i> operand is specified or if <i>input_file</i> is <tt>'-'</tt> . See
the INPUT FILES section.</p>
</blockquote>
<h4><a name="tag_04_158_07"></a>INPUT FILES</h4>
<blockquote>
<p>The input file shall be a text file.</p>
</blockquote>
<h4><a name="tag_04_158_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>The following environment variables shall affect the execution of <i>uniq</i>:</p>
<dl compact>
<dt><i>LANG</i></dt>
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
<dt><i>LC_ALL</i></dt>
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
<dt><i>LC_CTYPE</i></dt>
<dd>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 &lt;blank&gt; in the current
locale.</dd>
<dt><i>LC_MESSAGES</i></dt>
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard
error.</dd>
<dt><i>NLSPATH</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></dd>
</dl>
</blockquote>
<h4><a name="tag_04_158_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<h4><a name="tag_04_158_10"></a>STDOUT</h4>
<blockquote>
<p>The standard output shall be used only if no <i>output_file</i> operand is specified. See the OUTPUT FILES section.</p>
</blockquote>
<h4><a name="tag_04_158_11"></a>STDERR</h4>
<blockquote>
<p>The standard error shall be used only for diagnostic messages.</p>
</blockquote>
<h4><a name="tag_04_158_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>If the <b>-c</b> option is specified, the application shall ensure that the output file is empty or each line shall be of the
form:</p>
<pre>
<tt>"%d %s", &lt;</tt><i>number of duplicates</i><tt>&gt;, &lt;</tt><i>line</i><tt>&gt;
</tt>
</pre>
<p>otherwise, the application shall ensure that the output file is empty or each line shall be of the form:</p>
<pre>
<tt>"%s", &lt;</tt><i>line</i><tt>&gt;
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_158_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_158_14"></a>EXIT STATUS</h4>
<blockquote>
<p>The following exit values shall be returned:</p>
<dl compact>
<dt>&nbsp;0</dt>
<dd>The utility executed successfully.</dd>
<dt>&gt;0</dt>
<dd>An error occurred.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_158_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_158_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The <a href="../utilities/sort.html"><i>sort</i></a> utility can be used to cause repeated lines to be adjacent in the input
file.</p>
</blockquote>
<h4><a name="tag_04_158_17"></a>EXAMPLES</h4>
<blockquote>
<p>The following input file data (but flushed left) was used for a test series on <i>uniq</i>:</p>
<pre>
<tt>#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
</tt>
</pre>
<p>What follows is a series of test invocations of the <i>uniq</i> utility that use a mixture of <i>uniq</i> options against the
input file data. These tests verify the meaning of <i>adjacent</i>. The <i>uniq</i> utility views the input data as a sequence of
strings delimited by <tt>'\n'</tt> . Accordingly, for the <i>fields</i>th member of the sequence, <i>uniq</i> interprets unique or
repeated adjacent lines strictly relative to the <i>fields</i>+1th member.</p>
<ol>
<li>
<p>This first example tests the line counting option, comparing each line of the input file data starting from the second
field:</p>
<pre>
<tt>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
</tt>
</pre>
<p>The number <tt>'2'</tt> , prefixing the fifth line of output, signifies that the <i>uniq</i> utility detected a pair of repeated
lines. Given the input data, this can only be true when <i>uniq</i> is run using the <b>-f&nbsp;1</b> option (which shall cause
<i>uniq</i> to ignore the first field on each input line).</p>
</li>
<li>
<p>The second example tests the option to suppress unique lines, comparing each line of the input file data starting from the
second field:</p>
<pre>
<tt>uniq -d -f 1 uniq_0I.t
#05 foo0 bar0 foo1 bar1
</tt>
</pre>
</li>
<li>
<p>This test suppresses repeated lines, comparing each line of the input file data starting from the second field:</p>
<pre>
<tt>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
</tt>
</pre>
</li>
<li>
<p>This suppresses unique lines, comparing each line of the input file data starting from the third character:</p>
<pre>
<tt>uniq -d -s 2 uniq_0I.t
</tt>
</pre>
<p>In the last example, the <i>uniq</i> utility found no input matching the above criteria.</p>
</li>
</ol>
</blockquote>
<h4><a name="tag_04_158_18"></a>RATIONALE</h4>
<blockquote>
<p>Some historical implementations have limited lines to be 1080 bytes in length, which does not meet the implied {LINE_MAX}
limit.</p>
</blockquote>
<h4><a name="tag_04_158_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_158_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="comm.html"><i>comm</i></a> , <a href="sort.html"><i>sort</i></a></p>
</blockquote>
<h4><a name="tag_04_158_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 2.</p>
</blockquote>
<h4><a name="tag_04_158_22"></a>Issue 6</h4>
<blockquote>
<p>The obsolescent SYNOPSIS and associated text are removed.</p>
<p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>