j0h*_*j0h 4 command-line bash scripts
我喜欢该uniq
命令的作用,但它会在不同的行中查找重复项。即使在同一行中,我也想找到重复项。什么命令可以做到这一点?
考虑一下this line this this line
,我可能想知道“this”在同一行中出现了多少次。
有没有可以做到这一点的命令?
你可以做:
grep -Eo '[^[:blank:]]+' file.txt | sort | uniq -c
Run Code Online (Sandbox Code Playgroud)
grep -Eo '[^[:blank:]]+'
获取由任何空格分隔的文件单词
sort
对输出进行排序
uniq -c
字里行间
例子:
% grep -Eo '[^[:blank:]]+' <<<'this line this this line' | sort | uniq -c
2 line
3 this
Run Code Online (Sandbox Code Playgroud)