我在一个文件夹(d:\ text)中有多个文件。
使用gawk(在Windows中),我想以以下格式生成单词及其出现次数的列表:
a 12145 the 22483 but 754
等
答案 0 :(得分:0)
考虑输入:
$ ls ./in*
./in1.txt ./in2.txt
$ cat in*
What's up Buddy. How are you doin Buddy?
What's up Man. I am happy and good and awesome.
AWK用关联数组对单词进行计数,单词被视为字母字符(您将需要调优,还需要为大写/小写字母创建逻辑等)。请注意,还为空字符串添加了计数4:
$ gawk 'BEGIN { RS="[^A-Za-z]"; } { words[$0]++; } END { for ( i in words ) print(i " " words[i]); }' ./in*
happy 1
are 1
4
What 2
awesome 1
How 1
Buddy 2
and 2
I 1
up 2
good 1
doin 1
am 1
Man 1
you 1
s 2