多行正则表达式 [英] Multi line regex expression

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

问题描述

我有以下文件,我正在尝试使用 /\|\".*\"\|/gm 匹配 multi line..end here,但正则表达式使用 sed -e ':a;N;$!ba;s/\|\".*\"\|/abcxyz/gm' t >t.2,我不知道有什么问题.

I have the following file, and I'm trying to use /\|\".*\"\|/gm match multi line..end here, but the regex finds nothing using sed -e ':a;N;$!ba;s/\|\".*\"\|/abcxyz/gm' t > t.2, I can't find out what's wrong with it.

    |2012-10-12 13:41:08.067|2012-10-12 13:45:03.282|f||"multi line star t herer erj
jdkajdkfj 
   end here"|2017

推荐答案

这可能对你有用(GNU sed):

This might work for you (GNU sed):

sed -e ':a;N;$!ba;s/|".*"|/|"abcxyz"|/' file

|" 不需要被引用.如果 | 被引用,它充当交替元字符,即 this|that 意思是这个或那个.

The | and the " do not need to be quoted. If the | is quoted it acts as the alternation metacharacter i.e. this|that meaning this or that.

注意:a;N;$!ba 构造将整个文件放入内存中,因为 .* 是贪婪的,所以可能匹配多个记录.

N.B. The :a;N;$!ba construct slurps the entire file into memory and because the .* is greedy, more than one record may be matched.

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

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