小编Sam*_*ale的帖子

尝试使用脚本查找文件中单词的频率

我拥有的文件被调用test,它包含以下几行:

This is a test Test test test There are multiple tests.
Run Code Online (Sandbox Code Playgroud)

我希望输出是:

test@3 tests@1 multiple@1 is@1 are@1 a@1 This@1 There@1 Test@1
Run Code Online (Sandbox Code Playgroud)

我有以下脚本:

 cat $1 | tr ' ' '\n' > temp # put all words to a new line
    echo -n > file2.txt # clear file2.txt
    for line in $(cat temp)  # trace each line from temp file
    do
    # check if the current line is visited
     grep -q $line file2.txt 
     if [ $line==$temp] 
     then
    count= expr …
Run Code Online (Sandbox Code Playgroud)

scripting bash

3
推荐指数
1
解决办法
6669
查看次数

标签 统计

bash ×1

scripting ×1