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'''' –