Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- VERSION="0.2"
- #__________________________________________________________
- # Authors: Daren Karupudayyan (& phillips321.co.uk)
- # License: CC BY-SA 3.0
- # Use: paremeter replace
- # Released: www.phillips321.co.uk
- #
- # dirty script hopefully will replace 2 constant parameters as described below
- # target.xml is the file in which 2 parameters will be replaced
- # from file1.txt and file2.txt
- # the two parameters are constant xxx and yyy
- #
- # @DK - Do you mean you have a file [target.xml] and you want to find and replace 2 values within it?
- # Value xxx will be replaced with the contents of file1.txt and yyy with file2.txt?
- # If this is the case then the following code with do that
- #__________________________________________________________
- f_usage(){ #outputs usage information
- echo "MESSAGE: dk_replace_script.sh ${VERSION}"
- echo "MESSAGE: Usage: `basename ${0}` [location/of/target.xml]"
- echo "MESSAGE: # `basename ${0}` /jobs/company/fudgepacker.xml"
- echo "MESSAGE:"
- }
- f_yesorno(){ #returns 1 if yes is selected
- read -e CONFIRM
- case $CONFIRM in
- y|Y|YES|yes|Yes)
- return 1 ;;
- *)
- return 0 ;;
- esac
- }
- f_valueset(){ #checks to see if targets.xml is given
- if [ -z ${1} ]
- then
- f_usage
- exit 1
- fi
- TARGETXML="${1}"
- XXX=`cat file1.txt` # like the use of xxx :-D
- YYY=`cat file2.txt`
- echo "MESSAGE: using file ${TARGETXML}"
- echo "MESSAGE: XXX to be replaced as ${XXX}"
- echo "MESSAGE: YYY to be replaced as ${YYY}"
- }
- f_replacer(){
- echo "MESSAGE: replacing xxx with ${XXX}"
- echo "MESSAGE: replacing yyy with ${YYY}"
- sed s/xxx/${XXX}/g s/yyy/${YYY}/g ${TARGETXML} >> ${TARGETXML}_output.xml
- }
- f_confirm(){
- echo -n "MESSAGE: Is the above correct?(yes/no): "
- f_yesorno && exit 0
- f_replacer
- }
- f_valueset
- f_confirm
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement