使用 Perl 删除多行正则表达式 [英] Remove multiline regex with Perl

查看:83
本文介绍了使用 Perl 删除多行正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除设置属性 last-lrm-refresh(通常是一组设置中的最后一行)的行,其中输入看起来例如像这样:

I would like to remove a line which sets an attribute last-lrm-refresh (typically the last line in a group of settings) where input looks e.g. like this:

dc-version=1.1.16-94ff4df \
cluster-infrastructure=corosync \
maintenance-mode=false \
last-lrm-refresh=1523005561

以下不起作用.我究竟做错了什么?我安装了 Perl v5.20.2.

The following does not work. What am I doing wrong? I have Perl v5.20.2 installed.

perl -pe 's/ \\\n[ \t]+last-lrm-refresh=[0-9]+//smg' < in.out > out.txt

推荐答案

您正在阅读一行,其中一行被定义为以换行符结尾的多个字符,因此 \n[ \t] 不可能匹配.您可以通过将一行的定义更改为整个文件 (-0777) 来解决此问题.

You are reading a line at a time where a line is defined as a number of character ending with newline, so \n[ \t] can't possibly match. You can address this problem by changing the definition of a line to be the entire file (-0777).

perl -0777pe 's/ \\\n[ \t]+last-lrm-refresh=[0-9]+//' in.txt > out.txt

这篇关于使用 Perl 删除多行正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆