【发布时间】:2014-03-02 18:50:29
【问题描述】:
由于某种原因,uniq 似乎在比较不同行时识别换行符,并且识别文件换行符与 \n 不同(或者至少在我看来是这样)。
我想要它做的是这样的文件:
hello world hello hello
meh
hello
hello
并获得如下输出:
5 hello
1 world
1 meh
但是我的代码:
x=`sed 's/ /\n/g' $1 | uniq -c | sed 's/ //g'`
echo "$x"
正在输出这个:
1 hello
1 world
2 hello
1 meh
2 hello
【问题讨论】:
-
“出于某种原因”?为什么会有这样的惊喜?来自手册页:
uniq - report or omit repeated lines