Linux如何計算字串中空白的數目? - LinuxFranklin · 2012-08-19Table of ContentsPostCommentsRelated Posts請問在 shell script 中, 如何計算字串中空白的數目? 例如 "a bc d e" 應該有四個 " abc d " 應該有五個 -- LinuxAll CommentsOdelette2012-08-19我剛剛玩了一下計算文件中空白的方式,我用的是sed + wcEdwina2012-08-21cat test.txt | sed 's/[^ \t]//g' | wc -c把非' ', '\t'清掉再計算字元數,不過會多計一個EOFGary2012-08-26cat test.txt | sed 's/[ \t]/1 /g' | wc -wGary2012-08-30上面打錯..我想說的是進一部再把把空白換成字串計word數即可Connor2012-09-02(但這樣就有點畫蛇添足,減一還比較乾脆)Kumar2012-09-06用php/perl/C來解決比較快,拔釘子用鉗子比用起子方便Oscar2012-09-09唯一的樂趣就是單行把他完成...XDOlive2012-09-12樓上應該去玩 Obfuscated C CodeCatherine2012-09-16google來的: echo "a bc d e" | grep -o ' ' | wc -lGenevieve2012-09-19推樓上Olga2012-09-23echo -n "a bc d e" | sed 's/[^ ]//g' | wc -cRelated Posts請問fdisk有辦法更改分割區編號嗎?linux driver 編譯安裝問題備份換硬碟的問題…有關安裝問題Mail Server該如何移機才能降低影響
All Comments