Does anyone understand sed?

Post anything on anything here

Moderator: Moderators

Fri Aug 03, 2007 11:09 pm

  • Of all the programs on my computer, sed is the one that drives me insane every time I have to program with it. So, does anyone else have any incisive insight into it (or indeed awk)? This is what I'm trying to do:
    Change a value in XML.
    Eg.
    Replace <example>*</example>
    with <example>text</example>
    Ed
    Forum addon
     
    Posts: 1172
    Joined: Wed Mar 01, 2006 12:32 am
    Location: UK

Fri Aug 03, 2007 11:34 pm

  • If there's only one example-tag per line:
    Code: Select all
    sed 's/<example>.*<\/example>/<example>text<\/example>/g'

    (otherwise you have to replace .* with a more refined expression, that doesn't match </example>)
    User avatar
    KadaverJack
    Site admin and forum addon
     
    Posts: 1102
    Joined: Tue Feb 28, 2006 9:42 pm

Fri Aug 03, 2007 11:52 pm

  • KadaverJack wrote:If there's only one example-tag per line:
    Code: Select all
    sed 's/<example>.*<\/example>/<example>text<\/example>/g'

    (otherwise you have to replace .* with a more refined expression, that doesn't match </example>)

    It worked! 8)

    Guess I owe you a drink if we ever meet in real life.
    Ed
    Forum addon
     
    Posts: 1172
    Joined: Wed Mar 01, 2006 12:32 am
    Location: UK



Return to General Discussion




Information
  • Who is online
  • Users browsing this forum: No registered users and 1 guest