私はこのようなファイルを持っています:
This is a file with many words.
Some of the words appear more than once.
Some of the words only appear one time.
2列のリストを生成したいと思います。最初の列はどの単語が表示されるかを示し、2番目の列はそれらが表示される頻度を示します。次に例を示します。
this@1
is@1
a@1
file@1
with@1
many@1
words3
some@2
of@2
the@2
only@1
appear@2
more@1
than@1
one@1
once@1
time@1
- この作業を簡単にするために、リストを処理する前に、すべての句読点を削除し、すべてのテキストを小文字に変更します。
words
その周りに簡単な解決策がない限り、word
2つの別々の単語として数えることができます。
これまでのところ、私はこれを持っています:
sed -i "s/ /\n/g" ./file1.txt # put all words on a new line
while read line
do
count="$(grep -c $line file1.txt)"
echo $line"@"$count >> file2.txt # add word and frequency to file
done < ./file1.txt
sort -u -d # remove duplicate lines
何らかの理由で、これは各単語の後に「0」のみを表示しています。
ファイルに表示されるすべての単語のリストを頻度情報とともに生成するにはどうすればよいですか?