[英]Regex replace (sed or perl) with variable capture
I need to do a regex capture/repalce on a file with content like the following. 我需要对包含以下内容的文件执行正则表达式捕获/重新生成。 While I'm okay at matching things, I'm having trouble doing a capture replace.
虽然我可以匹配东西,但我在捕捉替换方面遇到了麻烦。
I'd like to do the following: 我想做以下事情:
So, for example, copy mytable(
would become hello mytable\\ncopy mytable(
. 所以,例如,
copy mytable(
将成为hello mytable\\ncopy mytable(
。
Sample Input 样本输入
copy tablename(
preferredid= 'c0»',
qid= 'c0»' with null(''),
qpi= 'c0»',
ptid= 'c0»' with null(''))...
into '/idata2/backup/core/eq.ingres'
尝试这个 :
sed 's/^copy \([^(]*\)($/hello \1\ncopy \1(/'
使用perl单线程
perl -i -pe 's/^(?=copy (\w+)\()/hello $1\n/' file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.