2011-03-28 60 views
2

說我有文件test.txt與內容:通過使用bash排序單字字閱讀整個文本文件的字

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam rhoncus dictum eros, eu molestie lectus cursus sit amet. Aliquam lectus erat, ultricies sit amet venenatis et, tincidunt eget magna. 

我需要的,它是閱讀整個文件字的字,但用...單詞排序。所以:

Aliquam 
Aliquam 
consectertur 
dictum 
... 

有什麼想法嗎?

回答

8
tr ' ' '\n' < test.txt | sort -u 

取出-u如果你想複製

2
for w in `cat test.txt`; do echo "$w"; done | sort 

刪除標點符號以及:

for w in `cat test.txt`; do echo "$w"; done | sed 's,[^a-zA-Z],,g' | sort 
0
tr "[[:space:]]" "\n" < file| sed 's/[[:punct:]]$//' | sort 

紅寶石(1.9+)

ruby -0777 -ne 'puts $_.split.map{ |x| x.gsub(/[[:punct:]]$/,"") }.sort' file