查找模式并添加到sed中 [英] Find pattern and append in sed

查看:75
本文介绍了查找模式并添加到sed中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难找到模式并在sed中的模式之前添加行

I am having difficulty to find a pattern and append line before the pattern in sed

假设我想用sed查找以下模式

Suppose i want to find the following pattern with sed

"stackov/er;flo.w users are great"

注意:要搜索的模式包含双引号,/,;和点然后在模式之前添加此行

Note:The pattern to be search contain double quotes , /, ; and dot And then append this line just before pattern

proud sta{ckov,er member

我的尝试

1. sed"|" stackov/er; flo.w用户很棒"| i \骄傲的sta {ckov,er成员"文件

2.

sed "/stackov/er;flo.w users are great|i\proud sta{ckov,er member" file

我试图用|代替/分隔符.然后使用\来转义/,但是没有用.

I tried to replace the / delimiter by | and then escaping / in pattern with \ but it didn't work.

任何帮助表示赞赏

推荐答案

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

This might work for you (GNU sed):

sed '/"stackov\/er;flo\.w users are great"/i\proud sta{ckov,er member' file

这篇关于查找模式并添加到sed中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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