本文介绍了在UNIX shell脚本中的列表中选择唯一的或不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个的ksh脚本返回值的一个长长的清单,换行符分开了,我只想看到独特的/不同的值。这是可能做到这一点?
举例来说,说我的输出目录中的文件后缀:
I want to see a list like:
解决方案
You might want to look at the uniq
and sort
applications.
./yourscript.ksh | sort | uniq
(FYI, yes, the sort is necessary in this command line, uniq
only strips duplicate lines that are immediately after each other)
EDIT:
Contrary to what has been posted by Aaron Digulla in relation to uniq
's commandline options:
Given the following input:
class jar jar jar bin bin java
uniq
will output all lines exactly once:
class jar bin java
uniq -d
will output all lines that appear more than once, and it will print them once:
jar bin
uniq -u
will output all lines that appear exactly once, and it will print them once:
class java
这篇关于在UNIX shell脚本中的列表中选择唯一的或不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!