Jer*_*Wik 13 command-line uniq
我在shell脚本中有这个代码:
sort input | uniq -c | sort -nr > output
Run Code Online (Sandbox Code Playgroud)
输入文件没有前面的空格,但输出有。我该如何解决?这是在 bash
Gou*_*nou 13
uniq的默认行为是在 7 个空格宽的行中右对齐频率,然后用一个空格将频率与项目分开。
来源:https : //www.thelinuxrain.com/articles/tweaking-uniq-c
使用 sed 删除前导空格:
$ sort input | uniq -c | sort -nr | sed 's/^\s*//' > output
Run Code Online (Sandbox Code Playgroud)
uniq -c添加前导空格。例如
$ echo test
test
$ echo test | uniq -c
1 test
Run Code Online (Sandbox Code Playgroud)
您可以在管道的末尾添加一个命令来删除它。例如
$ echo test | uniq -c | sed 's/^\s*//'
1 test
Run Code Online (Sandbox Code Playgroud)