how to edit XML using bash script?

后端 未结 4 1278
终归单人心
终归单人心 2020-11-29 11:29

1
2

Need to change values 1 and 2 from bash

4条回答
  •  盖世英雄少女心
    2020-11-29 12:18

    Since you give a sed example in one of the comments, I imagine you want a pure bash solution?

    while read input; do
      for field in tag tag1; do
        case $input in
          *"<$field>"*""* )
            pre=${input#*"<$field>"}
            suf=${input%""*}
            # Where are we supposed to be getting the replacement text from?
            input="${input%$pre}SOMETHING${input#$suf}"
            ;;
        esac
      done
      echo "$input"
    done
    

    This is completely unintelligent, and obviously only works on well-formed input with the start tag and the end tag on the same line, you can't have multiple instances of the same tag on the same line, the list of tags to substitute is hard-coded, etc.

    I cannot imagine a situation where this would be actually useful, and preferable to either a script or a proper XML approach.

提交回复
热议问题