問一個shell script的寫法 - Linux

Delia avatar
By Delia
at 2011-02-22T12:24

Table of Contents

各位版友好

小弟想要請教一個寫法

假如我有一個檔案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 每天想正妹 以當好人為樂 忘記正妹虧欠自己

--
Tags: Linux

All Comments

Una avatar
By Una
at 2011-02-26T04:24
cat test.dat | xargs | sed 's/ /\n/g' | sort
Cara avatar
By Cara
at 2011-02-27T19:23
這題如果用tcl寫就很簡單了。
Frederica avatar
By Frederica
at 2011-03-01T06:06
用C寫一個也很快@@
Sierra Rose avatar
By Sierra Rose
at 2011-03-03T01:22
一樓那樣就很好了
Ina avatar
By Ina
at 2011-03-06T13:22
ruby -e 'puts File.open("test.dat").read.split.sort'

sed 只使用到match的pattern部份

Faithe avatar
By Faithe
at 2011-02-22T11:54
檔案內容是類似這樣 Seagate 500G容量 SATA3 ST3500413AS/16M/SATA3/三年保, $1260 Seagate 1TB容量 SATA3 ST31000524AS/32M/SATA3/三年保, $1850 透過 ([0-9])+(G|T) 可以選取到500G 以及1T 但是在 ...

專業的鄉民

Robert avatar
By Robert
at 2011-02-21T21:56
第一次找書來一頁一頁看,學習使用Ubuntu作業系統 來替代Windows用 生活上一般電腦用途時,用Linux OS替代微軟OS 似乎是成為PTT專業鄉民的必備技能之一XD - ...

DNS設定檔

Hazel avatar
By Hazel
at 2011-02-21T20:13
OS: Ubuntu, 軟體: bind9, Master DNS IP: 假設為140.168.1.1 此Server管理一個C的網域,假設為140.168.1.0/24 此部DNS已由上層B網域的單位授權給我們自己管理正反解 目前架設的DNS似乎出了一點小問題 在內部網路的解析正反解都沒有問題 但是就 ...

Cent0S圖形介面亂碼?

Doris avatar
By Doris
at 2011-02-21T17:16
主機是CentOS 5.5 在開機進入圖形介面時候,設定網卡(圖形介面設定) 發現網卡的資訊中有些訊息是亂碼,且設定完成啟動的時候出現的視窗『也是亂碼』。 用google收尋一下問題,大都是講用pitty軟體sshd連進主機去出現亂碼的解決方法。 而我在/etc/sysconfig/i18n設定是 LAN ...

apt-get update問題

Charlotte avatar
By Charlotte
at 2011-02-21T15:56
最近使用apt-get update 最底下都會出現這些字串: ------------------------------------------------------------------------- (以上省略) W: 無法取得 http://tw.archive.ubuntu.com/ub ...