假设我有text.txt以下文件:
she likes cats, and he likes cats too.
我希望我的结果看起来像:
she 1
likes 2
cats 2
and 1
he 1
too 1
Run Code Online (Sandbox Code Playgroud)
如果space , .加入它会使脚本更容易,那就没问题了.
是否有一个简单的shell管道可以实现这一目标?
phs*_*phs 20
这是一个近在咫尺和我亲爱的单行:
cat text.txt | sed 's|[,.]||g' | tr ' ' '\n' | sort | uniq -c
Run Code Online (Sandbox Code Playgroud)
sed剥离标点符号(将正则表达式调整为味道),tr将结果每行放一个单词.