Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

This script uses sed to change all "" to "new stuff". How would one change just the "" after the yyy: using sed or anything else?

cat >sample.txt <<EOF
sed --expression='s/""/"new stuff"/' sample.txt
share|improve this question

migrated from stackoverflow.com Feb 12 '11 at 20:21

This question came from our site for professional and enthusiast programmers.

up vote 7 down vote accepted

I might not understand your question. If you want to replace ONLY the value after 'yyy' then use the previous answer. If you want to replace ANY values after 'yyy', try this one-liner:

sed --expression='/yyy/,$ s/""/"new stuff"/g' sample.txt

Haven't tested it :D...

share|improve this answer

Answer gleaned from O'Reilly - Sed & Awk 2nd Addition Around page 152

Write a script in a file

\"new stuff\"/

Apply this to your data with the usual

sed -f script sample.txt

This script says look for yyy:. When found read another line into the pattern buffer (sounds like Star Trek Transporter). Now do a s/ command on the joined lines. So we are looking for yyy: newline "". If found replace with yyy: \ notice backslash actual newline then "new stuff"

Good luck

share|improve this answer
see man page: unixhelp.ed.ac.uk/CGI/man-cgi?sed search for addresses paragraph – SashaN Jun 16 '09 at 20:55

I find once things get beyond a certain level of complexity, I switch to perl. s2p will handle the translation of your current sed solution. Or you could write it from scratch trivially. The search/replace expression will remain the same.

share|improve this answer

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.