次のようなスペースで区切られた単語を含む.txtファイルがあるとします。
But where is Esope the holly Bastard
But where is
そしてAwk関数:
cat /pathway/to/your/file.txt | tr ' ' '\n' | sort | uniq -c | awk '{print $2"@"$1}'
コンソールに次の出力が表示されます。
1 Bastard
1 Esope
1 holly
1 the
2 But
2 is
2 where
myFile.txtに印刷する方法は? 私は実際に30万行と200万語近くあります。結果をファイルに出力することをお勧めします。
編集:使用された回答(@Sudo_Oによる):
$ awk '{a[$1]++}END{for(k in a)print a[k],k}' RS=" |\n" myfile.txt | sort > myfileout.txt