0

This works

sed 's/[[:space:]]*<default>false/XXX/'

Why does prepending a > make it fail

sed 's/>[[:space:]]*<default>false/XXX/'

escaping the > does not help either. In other scenarios > seems to work just fine. Why not here?

text: <key type="b" name="launcher-minimize-window"> <default>false</default>

  • 2
    Does your text actually contain a newline? sed is line-oriented, so unless you're appending lines to the pattern or hold space, the trailing > from the previous line is not in the pattern space to be matched. – glenn jackman Feb 5 '15 at 18:37
  • By "fail" you don't mean that sed throws an error but that sed doesn't match? – Hauke Laging Feb 5 '15 at 18:38
  • @HaukeLaging doesn't match – nonanme Feb 5 '15 at 18:39
  • @glennjackman I thought newline is part of [[:space:]] – nonanme Feb 5 '15 at 18:40
  • 1
    It is, but sed reads it's input one line at a time, so unless you're doing some programming to accumulate the lines, there won't be any newlines to match. See also gnu.org/software/sed/manual/sed.html#Examples – glenn jackman Feb 5 '15 at 18:42
1

As you already informed by glenn jackman in comments:

sed reads it's input one line at a time, so unless you're doing some programming to accumulate the lines, there won't be any newlines to match

You are able to push GNU sed to treat all file as single line with -z option

-z, --null-data

      separate lines by NUL characters

So you can try

sed -z 's/>[[:space:]]*<default>false/XXX/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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