Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Replacing a string in an array using sed

$
0
0

I have the following file

<path name="headphones-hifi-dac-advanced"><ctl name="Es9018 Master Volume" value="0" /><ctl name="Es9018 AVC Volume" value="0" /><ctl name="Es9018 HEADSET TYPE" value="2" /></path><path name="headphones-hifi-dac-aux"><ctl name="Es9018 Master Volume" value="0" /><ctl name="Es9018 AVC Volume" value="0" /><ctl name="Es9018 HEADSET TYPE" value="3" /></path><path name="headphones-hifi-dacdop"><ctl name="Es9018 Master Volume" value="15" /><ctl name="Es9018 AVC Volume" value="1" /><ctl name="Es9018 HEADSET TYPE" value="1" /></path><path name="headphones-hifi-dacdop-advanced"><ctl name="Es9018 Master Volume" value="0" /><ctl name="Es9018 AVC Volume" value="0" /><ctl name="Es9018 HEADSET TYPE" value="2" /></path>

I want to replace each Es9018 Master Volume entries' values to a distinct one, see below:

<path name="headphones-hifi-dac-advanced"><ctl name="Es9018 Master Volume" value="5" /><ctl name="Es9018 AVC Volume" value="0" /><ctl name="Es9018 HEADSET TYPE" value="2" />

</path><path name="headphones-hifi-dac-aux"><ctl name="Es9018 Master Volume" value="15" /><ctl name="Es9018 AVC Volume" value="0" /><ctl name="Es9018 HEADSET TYPE" value="3" /></path><path name="headphones-hifi-dacdop"><ctl name="Es9018 Master Volume" value="20" /><ctl name="Es9018 AVC Volume" value="1" /><ctl name="Es9018 HEADSET TYPE" value="1" /></path><path name="headphones-hifi-dacdop-advanced"><ctl name="Es9018 Master Volume" value="0" /><ctl name="Es9018 AVC Volume" value="0" /><ctl name="Es9018 HEADSET TYPE" value="2" /></path>``

How do I achieve that using a sed logic?

I attempted

sed -i "/ *<path name=\"headphones-hifi-dac\">/a\ <ctl name=\"Es9018 AVC Volume\" value=\"0\" \/>"

But it ended up creating new entries instead of replacing current


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>