linux uniq命令_带有示例Linux uniq命令教程

linux uniq命令

linux uniq命令

Linux have a lot of tools to make daily work of system administrators easy. uniq is one of them. Uniq is a small tool with limited capabilities.

Linux有很多工具可以简化系统管理员的日常工作。 uniq就是其中之一。 Uniq是功能有限的小型工具。

uniq命令语法 (uniq Command Syntax)

Syntax is same as other most of the Linux commands.

语法与其他大多数Linux命令相同。

uniq [OPTION]... [INPUT [OUTPUT]]

uniq命令帮助 (uniq Command Help)

Simple and fast help about the options can be get like below.

关于这些选项的简单而快速的帮助可以从下面获得。

$ uniq --help
Help
uniq Command Help
uniq命令帮助

示例文件(Example File)

While looking at various options and features of the uniq command we need some sample text to use in the examples. Below there is a file named a.txt file.

在查看uniq命令的各种选项和功能时,我们需要一些示例文本以在示例中使用。 下面是一个名为a.txt文件。

This is Line 1 
This IS 2 
And an other Line
This IS 2
This IS 3
What a other Line

显示出现次数 (Show Occurrence Count)

This will show how many times each line occurred. This will create output by prefixing occurrence count with the lines.

这将显示每行发生了多少次。 这将通过在行的前面加上出现计数来创建输出。

$ uniq -c a.txt
Show Occurrence Count
Show Occurrence Count
显示出现次数

仅打印重复的行(Only Print Duplicate Lines)

There is another useful option which will show duplicate lines in the text file. This option -d will only show duplicate lines without giving any count.

还有另一个有用的选项,它将在文本文件中显示重复的行。 此选项-d将仅显示重复的行,而不给出任何计数。

$ uniq -d a.txt
Only Print Duplicate Lines
Only Print Duplicate Lines
仅打印重复的行

从比较中跳过指定的字段(Skip Specified Field From Comparing)

We can specify some fields for skipping them comparing. This can be useful to set the specific text to compare. As we have a text file where This column is the first field most of the lines. We can skip and start in the second field. Columns are delimited with spaces or tabs.

我们可以指定一些字段以跳过它们的比较。 这对于设置要比较的特定文本很有用。 由于我们有一个文本文件,其中“此列”是大多数行中的第一个字段。 我们可以跳过并从第二个字段开始。 列由空格或制表符分隔。

$ uniq -f 1 -c  a.txt
Skip Specified Field From Comparing
Skip Specified Field From Comparing
从比较中跳过指定的字段

从比较中跳过指定的字符(Skip Specified Chars From Comparing)

Some times it can be useful to skip some starting chars from the comparison. The index of the starting character can be specified with -s option like below. In this example, we will start comparing from 5th character.

有时,从比较中跳过一些起始字符可能很有用。 可以使用-s选项指定起始字符的索引,如下所示。 在此示例中,我们将从第5个字符开始比较。

$ uniq -s 5 -c  a.txt
Skip Specified Chars From Comparing
Skip Specified Chars From Comparing
从比较中跳过指定的字符

忽略uniq命令的区分大小写(Ignore Case sensitivity For uniq Command)

The sort command is by default case sensitive. Case sensitivity behaves differently for uppercase and lowercase characters. This default case sensitivity can be disabled with -i character like below.

默认情况下,sort命令区分大小写。 对于大写和小写字符,区分大小写的行为有所不同。 可以使用-i字符禁用此默认的区分大小写,如下所示。

$ uniq -i  a.txt

仅打印唯一行 (Only Print Unique Lines)

One of the most popular usages is printing only unique lines. Only unique lines can be printed with -u options.

最受欢迎的用法之一是仅打印唯一的行。 使用-u选项只能打印唯一的行。

$ uniq -u a.txt

uniq命令版本 (uniq Command Version)

Version can be printed with --version option.

可以使用--version选项打印--version

$ uniq --version
Version
Version
LEARN MORE  How To Run Parallel Jobs/Process/Programs in Bash
了解更多如何在Bash中运行并行作业/进程/程序

翻译自: https://www.poftut.com/linux-uniq-command-tutorial-examples/

linux uniq命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值