Skip to content

Instantly share code, notes, and snippets.

@bassaer
Last active May 12, 2018 15:45
Show Gist options
  • Save bassaer/e4e608727f4cb3dcfaba795f8ad4ee52 to your computer and use it in GitHub Desktop.
Save bassaer/e4e608727f4cb3dcfaba795f8ad4ee52 to your computer and use it in GitHub Desktop.
xmlファイル内をsedで置換するメモ ref: https://qiita.com/bassaer/items/067d982400c54ba9ef3c
~ vagrant@localhost
❯ cat foo
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="colors">
<item>amber</item>
<item>blue</item>
<item>blue grey</item>
<item>brown</item>
<item>cyan</item>
<item>deep orange</item>
<item>deep purple</item>
<item>green</item>
<item>grey</item>
<item>indigo</item>
<item>light blue</item>
<item>light green</item>
<item>lime</item>
<item>orange</item>
<item>pink</item>
<item>purple</item>
<item>red</item>
<item>teal</item>
<item>yellow</item>
</string-array>
</resources>
~ vagrant@localhost
❯ sed -i -E 's/(<item>)(\w+\s*\w*)(<\/item>)/\1\U\2\E\3/' foo
~ vagrant@localhost
❯ cat foo
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="colors">
<item>AMBER</item>
<item>BLUE</item>
<item>BLUE GREY</item>
<item>BROWN</item>
<item>CYAN</item>
<item>DEEP ORANGE</item>
<item>DEEP PURPLE</item>
<item>GREEN</item>
<item>GREY</item>
<item>INDIGO</item>
<item>LIGHT BLUE</item>
<item>LIGHT GREEN</item>
<item>LIME</item>
<item>ORANGE</item>
<item>PINK</item>
<item>PURPLE</item>
<item>RED</item>
<item>TEAL</item>
<item>YELLOW</item>
</string-array>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment