0
我想弄清楚每个单词在使用linux的文件中出现多少次。如何使用sed在linux中删除标点符号和单词的开头?
我已经通过使用下面的代码从我的文件中的每个单词放到一个新的行。
sed -i 's/ /\n/g' books2
我现在试图用空白替换单词的开始和结尾,因为有些单词包含标点符号。我目前正在通过使用下面的代码,但它似乎并没有工作。一旦我有了这个,我将能够运行一个命令来计算所有单词并返回所有单词的计数列表。有人能纠正我如何删除标点符号吗?
sed -i 's/\([^[:alpha:]]\)$//' books2 #this is my attempt to remove the punctuality at the end of the word
sed -i 's/\([^[:alpha:]]\)^.*//' books2 #this is my attempt to remove the punctuality from the front.
当我运行上面的任一行代码时,我的文件变为空。为什么是这样?
了解有关[GNU awk](https://www.gnu.org/software/gawk/)的更多信息 –