hi all
I have the following sed command in my script

sed -i "/$PARAM/s/$OLD/$BEW/g"           $FILE

this sed command replace the OLD value to new in the line that PARAMETER exsit

but I need also to ignore the "#" lines
how it can possible to change the sed syntax in order to ignore "#" lines? the solution must be only with sed not by perl!

link|improve this question

36% accept rate
Any particular reason for rejecting Perl? (perl -pe "next if /^#/; s/$OLD/$NEW/ if /$PARAM/") – grawity May 27 '10 at 13:06
in some case it not work for example on @ string – yael May 27 '10 at 13:30
for example perl -pe "next if /^#/; s/@d&/new_value/ if /param5/" this not replace the @d& with new_value and its work with sed if you have solution for the perl problem please I will hope that U have answer for that THX – yael May 27 '10 at 13:33
feedback

2 Answers

I think you want something like this:

/^[^#]*$PARAM/s/$OLD/$NEW/

replace $OLD by $NEW, if there's no hash mark before $PARAM

link|improve this answer
feedback

The b (branch) command should help:

/^#/b; /$PARAM/ s/$OLD/$NEW/g

From the manual of sed:

        b label
              Branch to label; if label is omitted, branch to end of script.

        [...]
link|improve this answer
please explain how to add the /^#/b; to my:sed -i "/$PARAM/s/$OLD/$BEW/g" ?? – yael May 27 '10 at 13:07
@yael: I already did. It's in the second line of my answer. – grawity May 27 '10 at 13:24
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.