sed - Bash delete line beetwen two pattern containing "/" -
this question has answer here:
- escape string sed replace pattern 14 answers
i've problem : able delete lines beetwen 2 pattern in file.
for example able delete line equals "line 1" beetwin "blablabla++" , "blablabla--"
line1 blablabla++ line1 line2 line3 blablabla-- line1
i've found way sed :
sed '/blablabla++/,/blablabla--/{/line1/d}' ./file
it working great. thing in real file more :
line1/script blablabla++ line1/script line2/script line3/script blablabla-- line1/script
how ?
edit
i've choosen bad example.
the thing don't know line need delete (the line sent parameter). know 1 thing sure contain "/" characters.
the thing when :
sed '/blablabla++/,/blablabla--/{/$1/d}' ./file
the "/" $1 contain mess sed.
you made bad example, because sed cmd works both input files. guess want match pattern containing /
sed.
if want match literal /
, can escape /
s, however, makes codes not easy read, particularly have many /
s wanted matched, can use \[c]pattern[c]
here [c]
char. example:
kent$ cat f //one// blablabla++ //one// //one two// //one three// blablabla-- //one// kent$ sed '/blablabla++/,/blablabla--/{\@//one//@d}' f //one// blablabla++ //one two// //one three// blablabla-- //one//
in above example, \@//one//@
pattern matching part.
Comments
Post a Comment