Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I have the following text in File.XML:


I would like to replace that with


I tried:

$ sed -i 's/<!--UpdateAccountGUIDs>UpdateAndExit</UpdateAccountGUIDs-->/<UpdateAccountGUIDs>UpdateAndExit</UpdateAccountGUIDs>/' File.XML

But get this error:

sed: -e expression #1, char 63: unknown option to `s'
share|improve this question

The issue is that your search pattern contains / which you are using as the replacement delimiter, you need to use another character for that or escape the /:

sed -i 's#<!--UpdateAccountGUIDs>UpdateAndExit</UpdateAccountGUIDs-->#<UpdateAccountGUIDs>UpdateAndExit</UpdateAccountGUIDs>#' File.XML


sed -i 's/<!--UpdateAccountGUIDs>UpdateAndExit<\/UpdateAccountGUIDs-->/<UpdateAccountGUIDs>UpdateAndExit<\/UpdateAccountGUIDs>/' File.XML

Note that you should never use regular expressions to parse [X]HTML.

Finally, as a general rule, when working with regular expressions, less is more. You should try to specify the simplest possible exclusive pattern rather than repeat all text. This not only makes your code much easier to read, it also avoids problems like the one you were facing. For example:

sed -i -r 's/<!--(UpdateAccountGUIDs.+?)-->/<\1>/' File.XML

Here, the -r enables extended regular expression syntax so we can use () to capture a group (without needing to escape the parentheses) and then refer to the captured text as \1. So, the command above simply looks for a comment that is adjacent to UpdateAccountGUIDs, extends till the first end of comment statement and then does the replacement.

share|improve this answer
@c0rp thanks, fixed. – terdon Apr 1 '14 at 16:25

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.