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/)的更多信息 –