Perl multiple match note 多行匹配 備忘

今天在Perl匹配替換的時(shí)候,發(fā)現(xiàn)有字串只能根據(jù)上一行定位,所以導(dǎo)致我要把2行都匹配出來,后做替換動(dòng)作

開始這樣寫的:

perl -pi -e 's/something/repalceString/g' /Users/Swift/Desktop/config.plist

經(jīng)過Google搜索在http://ask.xmodulo.com/search-and-replace-multi-line-string.html發(fā)現(xiàn)多一個(gè)-0的參數(shù)。

The "-i" option tells Perl to perform in-place editing, meaning that Perl reads the input file, makes substitutions, and writes the results back to the same input file. If you want to dry-run the changes, you can omit this option, in which case the results will be shown tostdoutwithout modifying the input file.

The "-0" option turns Perl into "file slurp" mode, where Perl reads the entire input file in one shot (intead of line by line). This enables multi-line search and replace.

The "-pe" option allows you to run Perl code (pattern matching and replacement in this case) and display output from the command line.

看man perl解釋:

[-0[octal/hexadecimal] ]

加上-0:

perl -0pi -e 's/(?<=something).*?(?=\/\>\s)/repalceString/g' /Users/file.plist

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,995評(píng)論 0 0
  • 想要這樣的一種愛情 沒有驚心動(dòng)魄的激烈 也沒有花前月下的浪漫 只有月光下藍(lán)色的牽念 指尖上淡雅如蓮的眷戀 還有清晨...
    伊清歡閱讀 229評(píng)論 1 2
  • 出現(xiàn)了問題,我一個(gè)人的力量是微弱的,于是在班級(jí)群里和家長進(jìn)行交流,家長的反應(yīng)是多數(shù)孩子在家書桌上擺放的物品滿當(dāng)當(dāng),...
    將深眠的紅薯叫醒閱讀 1,822評(píng)論 0 2
  • 豬肉楠閱讀 228評(píng)論 0 0
  • 自從離開家以后,沒和母親一起過過母親節(jié),只是電話里問候幾句。今年母親終于來到這座城市,以前總夢想著,等老人家來了以...
    尤冰夢閱讀 221評(píng)論 0 0

友情鏈接更多精彩內(nèi)容