1

I'm trying to replace a string upto the first instance of a second string with sed (in OS X). My sed command unfortunately replaces everything up to the last instance of the second string.

my text:

<li>lorem ipsum</li><li>dolor sit amet</li><li>something</li><li></li>

I need to remove <li>lorem ipsum</li> so that the new line looks like this:

<li>dolor sit amet</li><li>something</li><li></li>

my sed command unfortunately replaces the whole line:

sed -i "" 's:<li>lorem.*</li>::'

Do you have an idea how to solve this with sed?

Thanks AleV

AleV
  • 177
  • 1
  • 11
  • 2
    More generally, `sed 's:
  • lorem[^<]*
  • ::' -- that does not assume you have only letters in the text. Regular expressions, though, cannot in general parse XML which is not a regular language: You should be looking for an XML or HTML parser. – glenn jackman Jun 12 '13 at 10:14