日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sed编辑器基础

發(fā)布時(shí)間:2025/4/9 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sed编辑器基础 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一、 更多的替換選項(xiàng)
①替換標(biāo)記
  • root@localhost sed]# cat data4.txt
  • This is a test of the test script.
  • This is the second test of the test script.
  • [root@localhost sed]# sed 's/test/trial/' data4.txt
  • This is a trial of the test script.
  • This is the second trial of the test script.

  • 替換格式: ? s/pattern/replacement/flags
    4種可用的替換標(biāo)記:
    數(shù)字:表明新聞本將替換第幾處模式匹配的地方;
    g,表明新文本將會替換所有匹配的文本;
    p,表明原先行的內(nèi)容要打印出來;
    w file,將替換的結(jié)果寫到文件中。

    可以指定sed編輯器用新文本替換第幾處模式匹配的地方。
  • [root@localhost sed]# sed 's/test/trial/2' data4.txt
  • This is a test of the trial script.
  • This is the second test of the trial script.
  • 后面第二個(gè)test被替換掉了。

    用g替換標(biāo)記,能替換全部
  • [root@localhost sed]# sed 's/test/trial/g' data4.txt
  • This is a trial of the trial script.
  • This is the second trial of the trial script.

  • p替換標(biāo)記會只打印修改過的行,和-n選項(xiàng)(禁止輸出)一起使用。
  • [root@localhost sed]# cat data5.txt
  • This is a test line.
  • This is a different line.
  • [root@localhost sed]# sed -n 's/test/trial/p' data5.txt
  • This is a trial line.

  • ②替換字符
    替換(/),可以用其他字符替換字符串分隔符
  • [root@localhost sed]# sed -n 's!/bin/bash!/bin/csh!p' /etc/passwd
  • root:x:0:0:root:/root:/bin/csh
  • tq2440:x:500:500:tq2440:/home/tq2440:/bin/csh
  • win:x:501:501::/home/win:/bin/csh

  • 二、使用地址
    sed有兩種形式的行尋址:
    ①以數(shù)字形式表示行區(qū)間
    ②用文本模式來過濾出行
    [address] command

    1.數(shù)字方式的行尋址
  • [root@localhost sed]# sed '2s/dog/cat/' data1.txt
  • The quick brown fox jumps over the lazy dog.
  • The quick brown fox jumps over the lazy cat.
  • The quick brown fox jumps over the lazy dog.






  • 轉(zhuǎn)載于:https://www.cnblogs.com/ch122633/p/7363284.html

    總結(jié)

    以上是生活随笔為你收集整理的sed编辑器基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。