Perl multiple match note 多行匹配 备忘

今天在Perl匹配替换的时候,发现有字串只能根据上一行定位,所以导致我要把2行都匹配出来,后做替换动作

开始这样写的:

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

经过Google搜索在http://ask.xmodulo.com/search-and-replace-multi-line-string.html发现多一个-0的参数。

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 3,020评论 0 0
  • 想要这样的一种爱情 没有惊心动魄的激烈 也没有花前月下的浪漫 只有月光下蓝色的牵念 指尖上淡雅如莲的眷恋 还有清晨...
    伊清欢阅读 257评论 1 2
  • 出现了问题,我一个人的力量是微弱的,于是在班级群里和家长进行交流,家长的反应是多数孩子在家书桌上摆放的物品满当当,...
    将深眠的红薯叫醒阅读 1,849评论 0 2
  • 猪肉楠阅读 236评论 0 0
  • 自从离开家以后,没和母亲一起过过母亲节,只是电话里问候几句。今年母亲终于来到这座城市,以前总梦想着,等老人家来了以...
    尤冰梦阅读 225评论 0 0

友情链接更多精彩内容