Advertisement
phillips321

dk_replace_script.sh v0.2

May 15th, 2011
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.80 KB | None | 0 0
  1. #!/bin/bash
  2. VERSION="0.2"
  3. #__________________________________________________________
  4. # Authors:      Daren Karupudayyan (& phillips321.co.uk)
  5. # License:      CC BY-SA 3.0
  6. # Use:          paremeter replace
  7. # Released:     www.phillips321.co.uk
  8. #
  9. # dirty script hopefully will replace 2 constant parameters as described below
  10. #  target.xml is the file in which 2 parameters will be replaced
  11. #  from file1.txt and file2.txt
  12. #  the two parameters are constant xxx and yyy
  13. #
  14. # @DK - Do you mean you have a file [target.xml] and you want to find and replace 2 values within it?
  15. #       Value xxx will be replaced with the contents of file1.txt and yyy with file2.txt?
  16. #       If this is the case then the following code with do that
  17. #__________________________________________________________
  18.  
  19. f_usage(){      #outputs usage information
  20.     echo "MESSAGE: dk_replace_script.sh ${VERSION}"
  21.     echo "MESSAGE: Usage: `basename ${0}` [location/of/target.xml]"
  22.     echo "MESSAGE: # `basename ${0}` /jobs/company/fudgepacker.xml"
  23.     echo "MESSAGE:"
  24. }
  25. f_yesorno(){    #returns 1 if yes is selected
  26.     read -e CONFIRM
  27.     case $CONFIRM in
  28.         y|Y|YES|yes|Yes)
  29.             return 1 ;;
  30.         *)
  31.             return 0 ;;
  32.     esac
  33. }
  34. f_valueset(){   #checks to see if targets.xml is given
  35.     if [ -z ${1} ]
  36.     then
  37.         f_usage
  38.         exit 1
  39.     fi
  40.     TARGETXML="${1}"
  41.     XXX=`cat file1.txt`  # like the use of xxx :-D
  42.     YYY=`cat file2.txt`
  43.     echo "MESSAGE: using file ${TARGETXML}"
  44.     echo "MESSAGE: XXX to be replaced as ${XXX}"
  45.     echo "MESSAGE: YYY to be replaced as ${YYY}"
  46. }
  47. f_replacer(){
  48.     echo "MESSAGE: replacing xxx with ${XXX}"
  49.     echo "MESSAGE: replacing yyy with ${YYY}"
  50.     sed s/xxx/${XXX}/g s/yyy/${YYY}/g ${TARGETXML} >> ${TARGETXML}_output.xml
  51. }
  52. f_confirm(){
  53.     echo -n "MESSAGE: Is the above correct?(yes/no): "
  54.     f_yesorno && exit 0
  55.     f_replacer
  56. }
  57.  
  58. f_valueset
  59. f_confirm
  60. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement