sed常用執行個體__sed

來源:互聯網
上載者:User
sed 常用執行個體 1. 替換檔案中的資料

把檔案中還有“today”字串的資料行中的”Tom”字串替換成“John”:

sed -e '/today/s/Tom/John/g' input.dat

把檔案中第三行 的資料替換成句子“Young is better”:

sed -e '5c\Young is better' input.dat

把檔案中第3至10行的資料,替換成如下兩行資料”Young it better” “Haha”:

sed -e '3,10c\Young is better\Haha' input.dat
2. 搬動檔案中的資料

將檔案中的前40行資料,搬到檔案中第300後輸出:

sed -f mov.scr

mov.scr 檔案的內容:

1,40{Hd}300G
3. 刪除檔案中的資料

將檔案中所有空白行全部刪除:

sed -e '/^$/d' input.dat

將檔案內連續的空白行,刪除他們為一行:

sed -e '/^$/{N/^$/D}' input.dat
4. 搜素檔案中的資料

將檔案中含有”Tom”字串的資料行輸出:

sed -n -e '/Tom/p' input.dat

將檔案中含有”omega”字串的資料輸出:

sed -f gp.scr

gp.scr內容為:

/omega/bNhs/.*\n///omega/bgD

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.