Replace with sed a tag value under a specific section when matching a line

0

I would like to change a line when another line matchs under a section of a file using the sed command (or awk). Here is an exemple of the file :

Extract of MyFic.txt :

  <PlayList>
     ... Some tags ...
     <Album>X1</Album>
     ... oThers tags ...
     <Group>X2</Group>
     ... Some tags ...
   </PlayList>
   <PlayList>
      ... Some tags ...
      <Album>...</Album>
      ... oThers tags ...
      <Group>...</Group>
      ... Some tags ...
    </PlayList>

I would like to change the value of the tag Group by X3 when the tag Album value is X1 only into a PlayList section. The following command works fine :

sed -i '/< Album>X1/,/<\/PlayList>/ s/< Group>.*/< Group>X3<\/location>/' MyFic.txt

But this is not exactly what i really want. I would like someting like :

sed -i '/< PlayList>/,/<\/PlayList>/ {Containing  < Album>X1} s/< Group>.*/< Group>X3<\/location>/' MyFic.txt

I don't know how to code this part with the sed command : {Containing < Album>X1}

Do you have some idea ?

Octo

Posted 2015-01-23T08:20:18.790

Reputation: 1

Answers

0

To handle XML, use proper XML handling tools. For example, xsh:

cd //PlayList[Album='X1']/Group
set . 'X3'

choroba

Posted 2015-01-23T08:20:18.790

Reputation: 14 741