Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
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

I think you want something like this:


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

share|improve this answer

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.

share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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