bash - How to find and replace, skipping lines containing a particular character? -
i using sed
find , replace first appearance of pattern in file:
sed -i "0,\#pattern#s##replacement#" ./file.txt
how can tell skip of lines containing {
. here sample input:
this line not have item, skipped. line has pattern, has {, skipped too. line has pattern, , not character, changed.
here sample output:
this line not have item, skipped. line has pattern, has {, skipped too. line has replacement, , not character, changed.
- only 1 change made in entire file.
- if every line pattern contains
{
, no changes made file.
how can use sed
find , replace first appearance of item, skipping lines contain pattern, in case {
?
this might work (gnu sed):
sed '/{/b;/pattern/{s//replacement/;:a;n;ba}' file
skips lines containing {
on matching first pattern, substitutes replacement prints remaining lines end-of-file.
Comments
Post a Comment