Advertisement
Guest User

set_xml_dir.sh

a guest
Apr 26th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.96 KB | None | 0 0
  1. #!/sbin/sh
  2. # Feature XML Edit in directory
  3. # created by ~clumsy~
  4. # Usage:
  5. # set_xml_dir.sh <directory> <file_name_pattern> <feature_name> <value_to_change_to>
  6. # Note: If there is any spaces in a argument, capture them in quotations e.g. 'Some String'
  7. # Example_1: set_xml_dir.sh /system other.xml CscFeature_IMS_EnableVoLTE False
  8. # Example_2: set_xml_dir.sh /system other.xml CscFeature_Common_AutoConfigurationType 'NO_DFLT, SIMBASED_OMC'
  9.  
  10. dir=$1
  11. pattern=$2
  12. feature=$3
  13. value=$4
  14.  
  15. for file in $(find $dir -name '$pattern')
  16. do
  17.     lineNumber=0
  18.     lineNumber=`sed -n "/<${feature}>.*<\/${feature}>/=" $file`
  19.  
  20.     if [ $lineNumber > 0 ] ; then
  21.         echo "Found feature $feature in line $lineNumber and changing it to ${value}"
  22.         sed -i "${lineNumber} c<${feature}>${value}<\/${feature}>" $file
  23.     else
  24.         echo "Adding feature $feature to the feature set"
  25.         sed -i "/<\/FeatureSet>/i <${feature}>${value}<\/${feature}>" $file
  26.     fi
  27. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement