2019-04-21 11:50:48 +08:00

33 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="uniq">uniq</h1>
<p>报告或忽略文件中的重复行</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>uniq命令</strong> 用于报告或忽略文件中的重复行一般与sort命令结合使用。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">uniq(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-c或——count在每列旁边显示该行重复出现的次数
-d或--repeated仅显示重复出现的行列
-f&lt;栏位&gt;或--skip-fields=&lt;栏位&gt;:忽略比较指定的栏位;
-s&lt;字符位置&gt;或--skip-chars=&lt;字符位置&gt;:忽略比较指定的字符;
-u或——unique仅显示出一次的行列
-w&lt;字符位置&gt;或--check-chars=&lt;字符位置&gt;:指定要比较的字符。</code></pre>
<h3 id="参数">参数</h3>
<ul>
<li>输入文件:指定要去除的重复行文件。如果不指定此项,则从标准读取数据;</li>
<li>输出文件:指定要去除重复行后的内容要写入的输出文件。如果不指定此选项,则将内容显示到标准输出设备(显示终端)。</li>
</ul>
<h3 id="实例">实例</h3>
<p>删除重复行:</p>
<pre><code class="language-bash">uniq file.txt
sort file.txt | uniq
sort -u file.txt
</code></pre>
<p>只显示单一行:</p>
<pre><code class="language-bash">uniq -u file.txt
sort file.txt | uniq -u</code></pre>
<p>统计各行在文件中出现的次数:</p>
<pre><code class="language-bash">sort file.txt | uniq -c</code></pre>
<p>在文件中找出重复的行:</p>
<pre><code class="language-bash">sort file.txt | uniq -d</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->