shell特殊符_cut命令、sort_wc_uniq命令兔沃、tee_tr_split命令蒋得、shell特殊符號(下)

810 shell特殊符_cut命令

image.png
[root@localhost ~]#cat anaconda-ks.cfg |grep "Sys*"
# System authorization information
# System language
# System services
# System timezone
# System bootloader configuration
[root@localhost ~]##ls
[root@localhost ~]#ls
a1.txt  anaconda-ks.cfg  a.txt  d6z  d6z.tar.gz
[root@localhost ~]#a=321
[root@localhost ~]#b=123$a
[root@localhost ~]#echo $b
123321
[root@localhost ~]#b=123\$a
[root@localhost ~]#echo $b
123$a
管道相關(guān)的命令
[root@localhost ~]#cat anaconda-ks.cfg |head -2 | cut -d "S" -f 1
(截取字符串   cut -d 分隔符 -f 截取的數(shù)量)
#version=DEVEL
# 
[root@localhost ~]#cat anaconda-ks.cfg |head -2 | cut -d "S" -f 1,2
#version=DEVEL
# System authorization information
[root@localhost ~]#cat anaconda-ks.cfg |head -2 | cut -d "S" -f 1-3
#version=DEVEL
# System authorization information
[root@localhost ~]#cat anaconda-ks.cfg |head -2 | cut -c 5
(cut -c 第幾個字符)
s
s

811 sort_wc_uniq命令

[root@localhost ~]#cat a.txt 
2132145239786
wyuxcztaseyuiqw
123435ewqxdsa,.><>"|\]';.,/
jdioysaiud
sckgxzuyiasud78687
[root@localhost ~]#sort a.txt (排序)
123435ewqxdsa,.><>"|\]';.,/
2132145239786
jdioysaiud
sckgxzuyiasud78687
wyuxcztaseyuiqw
[root@localhost ~]#sort -n a.txt (以數(shù)字排序,其它為0)
jdioysaiud
sckgxzuyiasud78687
wyuxcztaseyuiqw
123435ewqxdsa,.><>"|\]';.,/
2132145239786
[root@localhost ~]#sort -r a.txt (反序)
wyuxcztaseyuiqw
sckgxzuyiasud78687
jdioysaiud
2132145239786
123435ewqxdsa,.><>"|\]';.,/
[root@localhost ~]#wc -l a.txt (統(tǒng)計行數(shù))
5 a.txt
[root@localhost ~]#wc -m a.txt (統(tǒng)計字符數(shù))
88 a.txt
[root@localhost ~]#wc -w a.txt (統(tǒng)計詞數(shù))
5 a.txt
[root@localhost ~]#sort a.txt |uniq -c(排序去重)
      1 123435ewqxdsa,.><>"|\]';.,/
      1 2132145239786
      1 jdioysaiud
      1 sckgxzuyiasud78687
      1 wyuxcztaseyuiqw

812 tee_tr_split命令

tee重定向并打印

[root@localhost ~]#cat /etc/passwd |head -2  |tee a.txt (tee重定向并打悠故琛)
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost ~]#sort /etc/passwd |head -2  |tee a.txt 
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost ~]#cat a.txt 
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin

tee -a 追加重定向并打印

[root@localhost ~]#sort /etc/passwd |head -2  |tee -a  a.txt 
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost ~]#cat a.txt 
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin

tr 替換字符

[root@localhost ~]#echo 'dasycxizijo'  |tr '[a-z]' '[A-Z]'
DASYCXIZIJO

split 切割 -d 指定大小分割

[root@localhost ~]#split -b 100 anaconda-ks.cfg 
[root@localhost ~]#ls -lh
總用量 712K
-rw-r--r--. 1 root root   70 1月  22 17:59 a1.txt
-rw-------. 1 root root 1.4K 12月 26 08:11 anaconda-ks.cfg
-rw-r--r--. 1 root root  140 1月  24 11:44 a.txt
drwxr-xr-x. 3 root root   91 1月  10 11:50 d6z
-rw-r--r--. 1 root root 640K 1月  10 17:14 d6z.tar.gz
-rw-r--r--. 1 root root  100 1月  24 11:54 xaa
-rw-r--r--. 1 root root  100 1月  24 11:54 xab
-rw-r--r--. 1 root root  100 1月  24 11:54 xac
-rw-r--r--. 1 root root  100 1月  24 11:54 xad
-rw-r--r--. 1 root root  100 1月  24 11:54 xae
-rw-r--r--. 1 root root  100 1月  24 11:54 xaf
-rw-r--r--. 1 root root  100 1月  24 11:54 xag
-rw-r--r--. 1 root root  100 1月  24 11:54 xah
-rw-r--r--. 1 root root  100 1月  24 11:54 xai
-rw-r--r--. 1 root root  100 1月  24 11:54 xaj
-rw-r--r--. 1 root root  100 1月  24 11:54 xak
-rw-r--r--. 1 root root  100 1月  24 11:54 xal
-rw-r--r--. 1 root root  100 1月  24 11:54 xam
-rw-r--r--. 1 root root  100 1月  24 11:54 xan
-rw-r--r--. 1 root root   18 1月  24 11:54 xao

split 切割 -l 指定行數(shù)分割

[root@localhost ~]#split -l 50 anaconda-ks.cfg 
[root@localhost ~]#ls -lh
總用量 660K
-rw-r--r--. 1 root root   70 1月  22 17:59 a1.txt
-rw-------. 1 root root 1.4K 12月 26 08:11 anaconda-ks.cfg
-rw-r--r--. 1 root root  140 1月  24 11:44 a.txt
drwxr-xr-x. 3 root root   91 1月  10 11:50 d6z
-rw-r--r--. 1 root root 640K 1月  10 17:14 d6z.tar.gz
-rw-r--r--. 1 root root 1.4K 1月  24 11:58 xaa
-rw-r--r--. 1 root root    5 1月  24 11:58 xab

split 切割 指定文件名

[root@localhost ~]#split -b 200 anaconda-ks.cfg aaa.
[root@localhost ~]#ls -lh
總用量 684K
-rw-r--r--. 1 root root   70 1月  22 17:59 a1.txt
-rw-r--r--. 1 root root  200 1月  24 12:02 aaa.aa
-rw-r--r--. 1 root root  200 1月  24 12:02 aaa.ab
-rw-r--r--. 1 root root  200 1月  24 12:02 aaa.ac
-rw-r--r--. 1 root root  200 1月  24 12:02 aaa.ad
-rw-r--r--. 1 root root  200 1月  24 12:02 aaa.ae
-rw-r--r--. 1 root root  200 1月  24 12:02 aaa.af
-rw-r--r--. 1 root root  200 1月  24 12:02 aaa.ag
-rw-r--r--. 1 root root   18 1月  24 12:02 aaa.ah
-rw-------. 1 root root 1.4K 12月 26 08:11 anaconda-ks.cfg
-rw-r--r--. 1 root root  140 1月  24 11:44 a.txt
drwxr-xr-x. 3 root root   91 1月  10 11:50 d6z
-rw-r--r--. 1 root root 640K 1月  10 17:14 d6z.tar.gz

813 shell特殊符號(下)

特殊符號

$變量的前綴额衙,!$組合 正則里面表示行尾
;多條命令寫到一行時用分號分割
命令1 || 命令2 當?shù)谝粋€命令成功時則只執(zhí)行第一個命令 當?shù)谝粋€命令不成功時則執(zhí)行第二個命令
命令1 && 命令2 當?shù)谝粋€命令成功時則兩個命令都執(zhí)行 當?shù)谝粋€命令不成功時不執(zhí)行第二個命令

[root@localhost ~]#a=1
[root@localhost ~]#echo $a
1
[root@localhost ~]#ls -lh anaconda-ks.cfg ; wc -l anaconda-ks.cfg 
-rw-------. 1 root root 1.4K 12月 26 08:11 anaconda-ks.cfg
51 anaconda-ks.cfg

相關(guān)測驗題目:http://ask.apelearn.com/question/5437
擴展
1. source exec 區(qū)別 http://alsww.blog.51cto.com/2001924/1113112
2. Linux特殊符號大全http://ask.apelearn.com/question/7720
3. sort并未按ASCII排序 http://blog.csdn.net/zenghui08/article/details/7938975

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末怕吴,一起剝皮案震驚了整個濱河市窍侧,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌转绷,老刑警劉巖伟件,帶你破解...
    沈念sama閱讀 221,695評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異议经,居然都是意外死亡斧账,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,569評論 3 399
  • 文/潘曉璐 我一進店門爸业,熙熙樓的掌柜王于貴愁眉苦臉地迎上來其骄,“玉大人,你說我怎么就攤上這事扯旷≌” “怎么了?”我有些...
    開封第一講書人閱讀 168,130評論 0 360
  • 文/不壞的土叔 我叫張陵钧忽,是天一觀的道長毯炮。 經(jīng)常有香客問我逼肯,道長,這世上最難降的妖魔是什么桃煎? 我笑而不...
    開封第一講書人閱讀 59,648評論 1 297
  • 正文 為了忘掉前任篮幢,我火速辦了婚禮,結(jié)果婚禮上为迈,老公的妹妹穿的比我還像新娘三椿。我一直安慰自己,他們只是感情好葫辐,可當我...
    茶點故事閱讀 68,655評論 6 397
  • 文/花漫 我一把揭開白布搜锰。 她就那樣靜靜地躺著,像睡著了一般耿战。 火紅的嫁衣襯著肌膚如雪蛋叼。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,268評論 1 309
  • 那天剂陡,我揣著相機與錄音狈涮,去河邊找鬼。 笑死鸭栖,一個胖子當著我的面吹牛歌馍,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播晕鹊,決...
    沈念sama閱讀 40,835評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼骆姐,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了捏题?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,740評論 0 276
  • 序言:老撾萬榮一對情侶失蹤肉渴,失蹤者是張志新(化名)和其女友劉穎公荧,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體同规,經(jīng)...
    沈念sama閱讀 46,286評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡循狰,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,375評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了券勺。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片绪钥。...
    茶點故事閱讀 40,505評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖关炼,靈堂內(nèi)的尸體忽然破棺而出程腹,到底是詐尸還是另有隱情,我是刑警寧澤儒拂,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布寸潦,位于F島的核電站色鸳,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏见转。R本人自食惡果不足惜命雀,卻給世界環(huán)境...
    茶點故事閱讀 41,873評論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望斩箫。 院中可真熱鬧吏砂,春花似錦、人聲如沸乘客。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,357評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽寨典。三九已至氛雪,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間耸成,已是汗流浹背报亩。 一陣腳步聲響...
    開封第一講書人閱讀 33,466評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留井氢,地道東北人弦追。 一個月前我還...
    沈念sama閱讀 48,921評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像花竞,于是被迫代替她去往敵國和親劲件。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,515評論 2 359

推薦閱讀更多精彩內(nèi)容