tags:

views:

28

answers:

1

I am using sed to extract parts of an XML I am interested in:

sed '/<car car_id="BMW" year="1999"/,/</car>/p' input

So what I really would like to get back is:

<car car_id="BMW" year="1999" color="blue> ... </car>

Instead I get back a bunch of other car elements.

+1  A: 

You need to use the -n option to prevent other lines from being printed and the selected lines from being double printed.

sed -n '/<car car_id="BMW" year="1999"/,/</car>/p' input

But there are better tools for manipulating XML (as Steven said).

Dennis Williamson