[問題] 問一個shell script的寫法

看板Linux作者 (Arim5566)時間15年前 (2011/02/22 12:24), 編輯推噓2(203)
留言5則, 5人參與, 最新討論串1/2 (看更多)
各位版友好 小弟想要請教一個寫法 假如我有一個檔案test.dat 內容為 abstract continue for false new switch assert default if package synchronized boolean do goto private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try true char final interface static void class finally long strictfp volatile const float native super while null 現在想要把他調整成每一行只有一個word,並且可以依照ASCII值做排列 例如 abstract assert boolean .... ... 排列那個我知道可以用sort 只是一行一個word不知道要怎麼寫比較好@@ 請問要怎麼寫比較好?? 感謝各位版友 -- ~宅男的四個徵兆~ ∠□ ○ ! * \○/ ★    (○ ? ╦╦└□ " ○□═ □   □> ║║√√ ╦══╦ ∥    |\ 一回家就上PTT 每天想正妹 以當好人為樂 忘記正妹虧欠自己 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.197.57 ※ 編輯: Arim 來自: 114.32.197.57 (02/22 12:26)

02/22 13:08, , 1F
cat test.dat | xargs | sed 's/ /\n/g' | sort
02/22 13:08, 1F

02/22 13:26, , 2F
這題如果用tcl寫就很簡單了。
02/22 13:26, 2F

02/22 16:23, , 3F
用C寫一個也很快@@
02/22 16:23, 3F

02/22 18:14, , 4F
一樓那樣就很好了
02/22 18:14, 4F

02/22 18:23, , 5F
ruby -e 'puts File.open("test.dat").read.split.sort'
02/22 18:23, 5F
文章代碼(AID): #1DOpg921 (Linux)
討論串 (同標題文章)
文章代碼(AID): #1DOpg921 (Linux)