0
我想用bash命令行utils编写这个脚本,为了好玩。bash cmdline tokenizer /相对频率直方图... uniq失败
# make the corpus
echo -e "this \t is a \n cor-pus; \nthis \t\nis \n\t sparta. \n" > corpus.txt
# munge, collapse whitespace, tokenize
cat corpus.txt | tr -d '[email protected]#$%^&*()-_=+' | tr '\t' ' ' | tr '\n' ' ' | tr -s ' ' | fmt -1 | uniq -c | sort -rn
我期待
2 this
2 is
1 a
1 corpus
1 sparta
,但我得到的管道fmt -1
时
1 this
1 is
1 a
1 corpus
1 this
1 is
1 sparta
uniq
失败。也许有eof字符我看不到cat -e
? uniq
如何决定线和什么是文件?
echo a a b | fmt -1 | uniq
做我也期待它,所以我不知道为什么... | fmt -1 | uniq | ...
在我的脚本不起作用。
感谢
'tr'\ t'''| tr'\ n'''| tr -s'''可以写成'tr -s'\ t \ n'''' –