Reputation: 6749
I am having difficulty to find a pattern and append line before the pattern in 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
My attempts
1.sed "|"stackov/er;flo.w users are great"|i\proud sta{ckov,er member" file
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.
Any help appreciated
Upvotes: 1
Views: 868
Reputation: 189926
Unless you're on Windows (in which case I don't know), you basically want the entire sed
script in single quotes, not double.
sed '\|"stackov/er;flo.w users are great"|i\proud sta{ckov,er member' file
You can make it work with double quotes as well, but unless you specifically require double quotes, you should default to single quotes. Read up on the shell's quoting behavior if you want to use it in the future as well.
Upvotes: 0
Reputation: 58578
This might work for you (GNU sed):
sed '/"stackov\/er;flo\.w users are great"/i\proud sta{ckov,er member' file
Upvotes: 3