Linux基本指令之sort、uniq、join、cut、paste、split、tr

sort:
sort命令將許多不同的域按不同的順序分類
sort命令的一般格式爲:
sort -cmu -o output_file [other options] +pos1 +pos2 input_files
下面簡要介紹一下 sort的參數:
-c 測試文件是否已經分類。
-m 合併兩個分類文件。
-u 刪除所有複製行。
-o 存儲sort結果的輸出文件名。

其他選項有:
-b 使用域進行分類時,忽略第一個空格。
-n 指定分類是域上的數字分類。
-t 域分隔符;用非空格或 tab鍵分隔域。
-r 對分類次序或比較求逆。
+n n 爲域號。使用此域號開始分類。
n n 爲域號。在分類比較時忽略此域,一般與 +n一起使用。
post1   傳遞到 m,n。m爲域號, n爲開始分類字符數;例如 4,6意即以第 5域分類,從第 7個字符開始。


sort啓動方式:
缺省情況下, sort認爲一個空格或一系列空格爲分隔符。要加入其他方式分隔,使用  -t選項。
sort執行時,先查看是否爲域分隔設置了 -t選項,如果設置了,則使用它來將記錄分隔成域0、域1等等;如果未設置,用空格代替。缺省時 sort將整個行排序,指定域號的情況例外。
sort的一個重要事實是它參照第一個域作爲域 0,域 1是第二個域,等等


命令行實例:
[root@redhat script]#cat video.txt 
Boy in Company C:HK:192:1292
Alien:HK:119:1982
The Hill:KL:63:2972
Aliens:HK:534:4892
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#sort -c video.txt 
sort: video.txt:2: disorder: Alien:HK:119:1982
[root@redhat script]#
[root@redhat script]#sort -t: video.txt 
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:534:4892
Boy in Company C:HK:192:1292
Star Wars:HK:301:4102
The Hill:KL:63:2972
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#sort -t: -r video.txt 
Toy Story:HK:239:3972
The Hill:KL:63:2972
Star Wars:HK:301:4102
Boy in Company C:HK:192:1292
Aliens:HK:534:4892
Alien:HK:119:1982
A Few Good Men:KL:445:5851
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#sort -t: +0 video.txt 
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:534:4892
Boy in Company C:HK:192:1292
Star Wars:HK:301:4102
The Hill:KL:63:2972
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#sort -t: +1 video.txt 
Alien:HK:119:1982
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
Star Wars:HK:301:4102
Aliens:HK:534:4892
A Few Good Men:KL:445:5851
The Hill:KL:63:2972
[root@redhat script]#
[root@redhat script]#sort -t: +2 video.txt 
Alien:HK:119:1982
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Aliens:HK:534:4892
The Hill:KL:63:2972
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#sort -t: +2n video.txt 
The Hill:KL:63:2972
Alien:HK:119:1982
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Aliens:HK:534:4892
[root@redhat script]#
[root@redhat script]# 
[root@redhat script]#
[root@redhat script]#cat video.txt 
Boy in Company C:HK:192:1292
Alien:HK:119:1982
The Hill:KL:63:2972
Aliens:HK:534:4892
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Toy Story:HK:239:3972
Alien:HK:119:1982
[root@redhat script]#
[root@redhat script]#sort -u video.txt 
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:534:4892
Boy in Company C:HK:192:1292
Star Wars:HK:301:4102
The Hill:KL:63:2972
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#sort -t: +3 video.txt 
Boy in Company C:HK:192:1292
Alien:HK:119:1982
The Hill:KL:63:2972
Toy Story:HK:239:3972
Star Wars:HK:301:4102
Aliens:HK:534:4892
A Few Good Men:KL:445:5851
[root@redhat script]#
[root@redhat script]#sort -t: -k4 video.txt 
Boy in Company C:HK:192:1292
Alien:HK:119:1982
The Hill:KL:63:2972
Toy Story:HK:239:3972
Star Wars:HK:301:4102
Aliens:HK:534:4892
A Few Good Men:KL:445:5851
[root@redhat script]#
[root@redhat script]#sort -t: -k1 video.txt 
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:534:4892
Boy in Company C:HK:192:1292
Star Wars:HK:301:4102
The Hill:KL:63:2972
Toy Story:HK:239:3972
[root@redhat script]#sort -t: -k2 video.txt 
Alien:HK:119:1982
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
Star Wars:HK:301:4102
Aliens:HK:534:4892
A Few Good Men:KL:445:5851
The Hill:KL:63:2972
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#sort -t: -k2 -k4 video.txt 
Alien:HK:119:1982
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
Star Wars:HK:301:4102
Aliens:HK:534:4892
A Few Good Men:KL:445:5851
The Hill:KL:63:2972
[root@redhat script]#
[root@redhat script]#sort -t: +1 +3 video.txt 
Alien:HK:119:1982
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
Star Wars:HK:301:4102
Aliens:HK:534:4892
A Few Good Men:KL:445:5851
The Hill:KL:63:2972
[root@redhat script]#sort -t: +1 -2 +3 video.txt 
Boy in Company C:HK:192:1292
Alien:HK:119:1982
Toy Story:HK:239:3972
Star Wars:HK:301:4102
Aliens:HK:534:4892
The Hill:KL:63:2972
A Few Good Men:KL:445:5851
[root@redhat script]#
[root@redhat script]#sort -t: +1.2 video.txt 
Alien:HK:119:1982
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Aliens:HK:534:4892
The Hill:KL:63:2972
[root@redhat script]#
[root@redhat script]#sort -t: +0.2 video.txt 
Star Wars:HK:301:4102
The Hill:KL:63:2972
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:534:4892
Boy in Company C:HK:192:1292
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#sort -t: +0.0 video.txt 
A Few Good Men:KL:445:5851
Alien:HK:119:1982
Aliens:HK:534:4892
Boy in Company C:HK:192:1292
Star Wars:HK:301:4102
The Hill:KL:63:2972
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#sort -t: -r -k4 video.txt | head -1
A Few Good Men:KL:445:5851
[root@redhat script]#
[root@redhat script]#sort -t: -r -k4 video.txt | head -3
A Few Good Men:KL:445:5851
Aliens:HK:534:4892
Star Wars:HK:301:4102
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#sort -t: -r -k4 video.txt | tail -1
Boy in Company C:HK:192:1292
[root@redhat script]#
Boy in Company C:HK:192:1292
[root@redhat script]#
[root@redhat script]#sort -t: -r -k4 video.txt | head 
A Few Good Men:KL:445:5851
Aliens:HK:534:4892
Star Wars:HK:301:4102
Toy Story:HK:239:3972
The Hill:KL:63:2972
Alien:HK:119:1982
Boy in Company C:HK:192:1292
[root@redhat script]#
[root@redhat script]#sort -t: -r -k4 video.txt | tail 
A Few Good Men:KL:445:5851
Aliens:HK:534:4892
Star Wars:HK:301:4102
Toy Story:HK:239:3972
The Hill:KL:63:2972
Alien:HK:119:1982
Boy in Company C:HK:192:1292
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#cat video.txt 
Boy in Company C:HK:192:1292
Alien:HK:119:1982
The Hill:KL:63:2972
Aliens:HK:534:4892
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#cat video2.txt 
111111111111111111111
222222222222222222222
333333333333333333333
[root@redhat script]#
[root@redhat script]#sort -t: -m video.txt video2.txt 
111111111111111111111
222222222222222222222
333333333333333333333
Boy in Company C:HK:192:1292
Alien:HK:119:1982
The Hill:KL:63:2972
Aliens:HK:534:4892
Star Wars:HK:301:4102
A Few Good Men:KL:445:5851
Toy Story:HK:239:3972
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#cat /etc/passwd | sort -t: +0 | awk -F":" '{print $1}'
adm
apache
bin
daemon
dbus
ftp
games
gdm
gopher
haldaemon
halt
htt
lp
mailnull
mail
netdump
news
nfsnobody
nobody
nscd
ntp
operator
pcap
root
rpcuser
rpc
rpm
shutdown
smmsp
sshd
sync
uucp
vcsa
xfs
yezhaohui2
yezhaohui
[root@redhat script]#
[root@redhat script]#




uniq:
uniq用來從一個文本文件中去除或禁止重複行。一般 uniq假定文件已分類,並且結果正確。 我們並不強制要求這樣做,如果願意,可以使用任何非排序文本,甚至是無規律行。
可以認爲 uniq有點像 sort命令中唯一性選項。對,在某種程度上講正是如此,但兩者有區別。


其選項含義:
-u   只顯示不重複行。
-d   只顯示有重複數據行,每種重複行只顯示其中一行
-c   打印每一重複行出現次數。
-fn  n爲數字,前n-1個域被忽略。 一些系統不識別 -f選項,這時替代使用 -nn。


命令行實例:
[root@redhat script]#cat myfile.txt 
May Day
May Day
May Day
Going Down
May Day
[root@redhat script]#
[root@redhat script]#uniq myfile.txt 
May Day
Going Down
May Day
[root@redhat script]#
[root@redhat script]#sort -u myfile.txt 
Going Down
May Day
[root@redhat script]#
[root@redhat script]#uniq -c myfile.txt 
      3 May Day
      1 Going Down
      1 May Day
[root@redhat script]#
[root@redhat script]#uniq -d myfile.txt 
May Day
[root@redhat script]#
[root@redhat script]#cat parts.txt 
AK123 OP
DK122 OP
EK999 OP
[root@redhat script]#
[root@redhat script]#uniq -c parts.txt 
      1 AK123 OP
      1 DK122 OP
      1 EK999 OP
[root@redhat script]#
[root@redhat script]#uniq -f2 parts.txt 
AK123 OP
[root@redhat script]#
[root@redhat script]#uniq -c -f2 parts.txt 
      3 AK123 OP
[root@redhat script]#
[root@redhat script]





join:
join用來將來自兩個分類文本文件的行連在一起。
文本文件中的域通常由空格或 tab鍵分隔,但如果願意,可以指定其他的域分隔符。一些 系統要求使用 join時文件域要少於 20,爲公平起見,如果域大於 20,應使用 DBMS系統。

讓我們看看它的可用選項列表:
an  n 爲一數字,用於連接時從文件 n中顯示不匹配行。例如, -a1顯示第一個文件的不匹 配行, -a2爲從第二個文件中顯示不匹配行。
o n.m  n 爲文件號, m爲域號。 1.3表示只顯示文件 1第三域,每個 n,m必須用逗號分隔, 如1.3,2.1。
j n m   n爲文件號, m爲域號。使用其他域做連接域。
t   域分隔符。用來設置非空格或 tab鍵的域分隔符。例如,指定冒號做域分隔符 -t:。


命令行實例:
[root@redhat script]#cat names.txt 
M.Golls 12 Hidd Rd
P.Heller The Acre
P.Willey 132 The Grove
T.Norms 84 Connaught Rd
K.Fletch 23 Woodlea
[root@redhat script]#
[root@redhat script]#cat town.txt 
M.Golls Norwich NRD
P.Willey Galashiels GDD
T.Norms Brandon BSL
K.Fletch Mildenhall MAF
[root@redhat script]#
[root@redhat script]#join names.txt  town.txt 
M.Golls 12 Hidd Rd Norwich NRD
P.Willey 132 The Grove Galashiels GDD
T.Norms 84 Connaught Rd Brandon BSL
K.Fletch 23 Woodlea Mildenhall MAF
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#join -a1 names.txt  town.txt 
M.Golls 12 Hidd Rd Norwich NRD
P.Heller The Acre
P.Willey 132 The Grove Galashiels GDD
T.Norms 84 Connaught Rd Brandon BSL
K.Fletch 23 Woodlea Mildenhall MAF
[root@redhat script]#
[root@redhat script]#join -a2 names.txt  town.txt 
M.Golls 12 Hidd Rd Norwich NRD
P.Willey 132 The Grove Galashiels GDD
T.Norms 84 Connaught Rd Brandon BSL
K.Fletch 23 Woodlea Mildenhall MAF
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#join -a1 -a2 names.txt  town.txt 
M.Golls 12 Hidd Rd Norwich NRD
P.Heller The Acre
P.Willey 132 The Grove Galashiels GDD
T.Norms 84 Connaught Rd Brandon BSL
K.Fletch 23 Woodlea Mildenhall MAF
[root@redhat script]#
[root@redhat script]#join -o 1.1 names.txt  town.txt 
M.Golls
P.Willey
T.Norms
K.Fletch
[root@redhat script]#
[root@redhat script]#join -o 1.2 names.txt  town.txt 
12
132
84
23
[root@redhat script]#
[root@redhat script]#join -o 2.1 names.txt  town.txt 
M.Golls
P.Willey
T.Norms
K.Fletch
[root@redhat script]#
[root@redhat script]#join -o 2.2 names.txt  town.txt 
Norwich
Galashiels
Brandon
Mildenhall
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#cat names.txt 
M.Golls 123 aaa
P.Heller 22 bbb
P.Willey 132 ccc
T.Norms 84 ddd
K.Fletch 45 eee
[root@redhat script]#
[root@redhat script]#cat town.txt 
M.Golls Norwich NRD aaa
P.Willey Galashiels GDD bbb
T.Norms Brandon BSL ccc
K.Fletch Mildenhall MAF eee
[root@redhat script]#
[root@redhat script]#join names.txt  town.txt 
M.Golls 123 aaa Norwich NRD aaa
P.Willey 132 ccc Galashiels GDD bbb
T.Norms 84 ddd Brandon BSL ccc
K.Fletch 45 eee Mildenhall MAF eee
[root@redhat script]#
[root@redhat script]#join -j1 3 -j2 4 names.txt  town.txt 
aaa M.Golls 123 M.Golls Norwich NRD
bbb P.Heller 22 P.Willey Galashiels GDD
ccc P.Willey 132 T.Norms Brandon BSL
eee K.Fletch 45 K.Fletch Mildenhall MAF
[root@redhat script]#
[root@redhat script]#







cut:
cut用來從標準輸入或文本文件中剪切列或域。剪切文本可以將之粘貼到一個文本文件。
cut一般格式爲:
cut [options] file1 file2
下面介紹其可用選項:
-c list  指定剪切字符數。
-f field  指定剪切域數。
-d   指定與空格和 tab鍵不同的域分隔符。
-c用來指定剪切範圍,如下所示:
-c1,5-7  剪切第 1個字符,然後是第 5到第7個字符。
-c1-50  剪切前 50個字符。
-f 格式與 -c相同。
-f 1 ,5  剪切 第1域,第 5域。
-f1,10-12  剪切第 1域,第 10域到第 12域。


命令行實例:
[root@redhat script]#cat pers 
P.Jones:Office Runner:ID897
S.Round:UNIX admin:ID666
L.Clip:Personl Chief:ID982
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#cut -d: -f1 pers 
P.Jones
S.Round
L.Clip
[root@redhat script]#
[root@redhat script]#cut -d: -f2 pers 
Office Runner
UNIX admin
Personl Chief
[root@redhat script]#
[root@redhat script]#cut -d: -f3 pers 
ID897
ID666
ID982
[root@redhat script]#
[root@redhat script]#cut -d: -f1,3 pers 
P.Jones:ID897
S.Round:ID666
L.Clip:ID982
[root@redhat script]#
[root@redhat script]#who
root     pts/0        Dec  7 05:36 (192.168.245.1)
root     pts/1        Dec  7 05:51 (192.168.245.1)
[root@redhat script]#
[root@redhat script]#who | cut -c1-2
ro
ro
[root@redhat script]#who | cut -c1-4
root
root
[root@redhat script]#
[root@redhat script]#who | cut -c1-14
root     pts/0
root     pts/1
[root@redhat script]#
[root@redhat script]#



paste:
paste將按行將不同文件行信息放在一行。缺省情況下, paste連接時,用空格或 tab鍵分隔 新行中不同文本,除非指定 -d選項,它將成爲域分隔符。
paste格式爲;
paste -d -s -file1 file2
選項含義如下:
-d   指定不同於空格或 tab鍵的域分隔符。例如用 @分隔域,使用 -d@。
-s   將每個文件合併成行而不是按行粘貼。
-   使用標準輸入。例如 ls -l |paste ,意即只在一列上顯示輸出。 



命令行實例:
[root@redhat script]#cut -d: -f1 pers > pas1
[root@redhat script]#cat pas1 
P.Jones
S.Round
L.Clip
[root@redhat script]#
[root@redhat script]#cut -d: -f3 pers > pas2
[root@redhat script]#cat pas2
ID897
ID666
ID982
[root@redhat script]#
[root@redhat script]#paste pas1 pas2
P.JonesID897
S.RoundID666
L.ClipID982
[root@redhat script]#
[root@redhat script]#paste pas2 pas1
ID897P.Jones
ID666S.Round
ID982L.Clip
[root@redhat script]#
[root@redhat script]#paste -d: pas2 pas1
ID897:P.Jones
ID666:S.Round
ID982:L.Clip
[root@redhat script]#
[root@redhat script]#paste -s pas2 pas1
ID897ID666 ID982
P.JonesS.RoundL.Clip
[root@redhat script]#
[root@redhat script]#





split:
split用來將大文件分割成小文件。有時文件越來越大,傳送這些文件時,首先將其分割可 能更容易。使用 vi或其他工具諸如 sort時,如果文件對於工作緩衝區太大,也會存在一些問題。 因此有時沒有選擇餘地,必須將文件分割成小的碎片。
split命令一般格式:
split -output_file-size input-filename output-filename

這裏output-file-size指的是文本文件被分割的行數。 split查看文件時, output-file-size選項 指定將文件按每個最多 1000行分割。如果有個文件有 2800行,那麼將分割成 3個文件,分別有1000、1000、800行。每個文件格式爲 x[aa]到x[zz],x爲文件名首字母, [aa]、[zz]爲文件名剩 餘部分順序字符組合。

命令行實例:
[root@redhat split]#pwd
/root/yzh/script/split
[root@redhat split]#
[root@redhat split]#ll
總用量 4
-rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
[root@redhat split]#
[root@redhat split]#cat split1 
this is line1
this is line2
this is line3
this is line4
this is line5
this is line6
[root@redhat split]#
[root@redhat split]#split split1 
[root@redhat split]#ll
總用量 8
-rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
-rw-r--r--  1 root root 84 2011/12/07 07:06:15 xaa
[root@redhat split]#
[root@redhat split]#cat xaa 
this is line1
this is line2
this is line3
this is line4
this is line5
this is line6
[root@redhat split]#
[root@redhat split]#rm -rf xaa
[root@redhat split]#ll
總用量 4
-rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
[root@redhat split]#
[root@redhat split]#split -2 split1 
[root@redhat split]#ll
總用量 16
-rwxrwxrwx  1 root root 84 2011/12/07 07:04:20 split1
-rw-r--r--  1 root root 28 2011/12/07 07:06:46 xaa
-rw-r--r--  1 root root 28 2011/12/07 07:06:46 xab
-rw-r--r--  1 root root 28 2011/12/07 07:06:46 xac
[root@redhat split]#
[root@redhat split]#cat xaa && echo ======= && cat xab && echo ======= && cat  xac
this is line1
this is line2
=======
this is line3
this is line4
=======
this is line5
this is line6
[root@redhat split]#





tr:
tr用來從標準輸入中通過替換或刪除操作進行字符轉換。 tr主要用於刪除文件中控制字符 或進行字符轉換。
使用 tr時要轉換兩個字符串:字符串 1用於查詢,字符串2用於處理各種轉換。 tr剛執行時,字符串 1中的字符被映射到字符串 2中的字符,然後轉換操作開始。
指定字符串 1或字符串 2的內容時,只能使用單字符或字符串範圍。
命令格式爲:
tr-c-d-s["string1_to_translate_from"]["string2_to_t riannpsulta_te_to" ]
file
這裏:
-c   用字符串 1中字符集的補集替換此字符集,要求字符集爲 ASCII。
-d   刪除字符串 1中所有輸入字符。
-s   刪除所有重複出現字符序列,只保留第一個;即將重複出現字符串壓縮爲一個字符串。
Input-file是轉換文件名。雖然可以使用其他格式輸入,但這種格式最常用。


字符範圍:
[a-z]a-z內的字符組成的字符串。 
[A-Z]   A-Z內的字符組成的字符串。 
[0-9]數字串。
/octal   一個三位的八進制數,對應有效的 ASCII字符。
[O*n]   表示字符 O重複出現指定次數 n。因此 [O*2]匹配OO的字符串。 大部分 tr變種支持字符類和速記控制字符。字符類格式爲 [:class],包含數字、希臘字母、空行、小寫、大寫、 cntrl鍵、空格、點記符、圖形等等。



tr中特定控制字符的不同表達方式:
速記符含義八進制方式
\aCtrl-G 鈴聲 \007
\bCtrl-H 退格符 \010
\fCtrl-L 走行換頁\014
\nCtrl-J 新行 \012
\rCtrl-M 回車 \015
\t      Ctrl-I tab鍵    \011
\vCtrl-X        \030



命令行實例:(無轉換控制字符的例子)
[root@redhat script]#cat oops.txt 
And the cowwwwws went homeeeeeee
Or did theyyyy
[root@redhat script]#tr -s "[a-z]" < oops.txt 
And the cows went home
Or did they
[root@redhat script]#
[root@redhat script]#tr -s "[A-Z]" < oops.txt 
And the cowwwwws went homeeeeeee
Or did theyyyy
[root@redhat script]#
[root@redhat script]#cat oops.txt | tr -s "[a-z]" 
And the cows went home
Or did they
[root@redhat script]#
[root@redhat script]#cat oops.txt 
And the cowwwwws went homeeeeeee


Or did theyyyy




ssssssssssssssssssssssssssssss
dd






11111111111111111111111111
[root@redhat script]#
[root@redhat script]#tr -s ["\n"] < oops.txt 
And the cowwwwws went homeeeeeee
Or did theyyyy
ssssssssssssssssssssssssssssss
dd
11111111111111111111111111
[root@redhat script]#
[root@redhat script]#tr -s [a-z] < oops.txt 
And the cows went home


Or did they




s
d






11111111111111111111111111
[root@redhat script]#
[root@redhat script]#tr -s '[a-z]' < oops.txt 
And the cows went home


Or did they




s
d






11111111111111111111111111
[root@redhat script]#
[root@redhat script]#tr -s '["\n"]' < oops.txt 
And the cowwwwws went homeeeeeee
Or did theyyyy
ssssssssssssssssssssssssssssss
dd
11111111111111111111111111
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[a-z]" "[A-Z]"
MAY DAY,MAY DAY,GOING DOWN...
[root@redhat script]#
[root@redhat script]#
[root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[:lower:]" "[:upper:]"
MAY DAY,MAY DAY,GOING DOWN...
[root@redhat script]#
[root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[A-Z]" "[a-z]"
may day,may day,going down...
[root@redhat script]#
[root@redhat script]#echo "May Day,May Day,Going Down..." | tr "[:upper:]" "[:lower:]"
may day,may day,going down...
[root@redhat script]#
[root@redhat script]#echo "monday123" | tr -c "[a-z]" "[\012*]"
monday






You have new mail in /var/spool/mail/root
[root@redhat script]#
[root@redhat script]#echo "monday12" | tr -c "[a-z]" "[\012*]"
monday




[root@redhat script]#echo "monday1" | tr -c "[a-z]" "[\012*]"
monday


[root@redhat script]#echo "monday" | tr -c "[a-z]" "[\012*]"
monday
[root@redhat script]#
[root@redhat script]#echo "0000 hdisk5" | tr "[0*4]" "-"
---- hdisk5
[root@redhat script]#

發佈了81 篇原創文章 · 獲贊 61 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章