Sed\Awk的一些用法

來源:互聯網
上載者:User


Sed\Awk的一些用法 sed 非互動式流編輯器   www.2cto.com  sed '1,4d' myfile   #刪除1到4行資料 sed '/La/d' myfile   #刪除含有La的資料行 //代表搜尋 sed '/[0-9]\{3\}/d'    #myfile 把含有3位元的行刪除,剩下的顯示 sed '/^$/d' myfile    #刪除myfile的空白行,^表開頭,$表尾部 sed '/La/!d' myfile    #把不含La的資料行刪除 sed  -n 'La/p' myfie     #把含有La的資料行顯示出來,-n只顯示符合樣式資料行 sed -n 's/La/Oo/gp' myfile    #全部把La替換成Oo,並顯示 sed -n 's/La//p' myfile     #把每一行第一個出現的La刪除 sed 's/^...//' myfile      #把每一行開頭的3個字元刪除 sed 's/...$//' myfile      #把每一行末尾3個字元刪除 sed -n 's/\(La\)/\1Oo/p' myfile      #把找到的La存起來,用\1取回來再使用 sed -n '/AAA/s/234/567/p' myfile     #找到含AAA的那行,將234換成567 sed -n '/AAA/,/DDD/s/B/567/p' myfile     #將含有AAA到含有DDD的那幾行,將其中的B換成567 sed -n '2,4s/B/567/p' myfile       #從第2行到第4行,都將其中的B換成567  awk  文本切割工具ps auxw |awk '{print $2}'         #擷取系統當前pid列表 awk '/La/' myfile      #顯示含La的資料行 awk '{print $1,$2}' myfile      #顯示myfile每一行的第1和第2個欄位 awk '/La/{print $1,$2}'       #將含有La關鍵詞的第1和第2個欄位顯示 awk -F: '/^user1/{print $3,$4}' /etc/passwd       #使用選項-F,指定:為分隔字元列印帳號user1的uid、gid awk -F: 'BEGIN{OFS="+++"}'/^user1/{ print $1,$2,$3,$4,$5 }' /etc/passwd       #以:為分隔字元,+++為輸出欄位分隔符號,將user1的第1~5 欄顯示 ifconfig |grep 'inet addr:' | grep Bcast |awk '{print $2}' |awk -F: '{print $2}'      #取得網卡的IP cat /proc/net/dev |awk -F: '/eth.:|ppp.:|wlan.:/{print $1}'        #取得網路裝置名稱 cat /proc/meminfo |awk '/MemTotal/{print $2}'        #取得記憶體大小 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.