I want to replace the text with the PATHTOEXPORTcontents of a variable passed on the command line, in which there will be a folder path (for example, /Dev_Content/AIX/Apache)
I came across this article , which discusses how to use sedto replace values in an XML file with another.
However, not using sedbefore, I'm not sure how to read the directions.
The script looks like this:
if [ $# -ne 3 ]; then
echo 1>&2 "This script replaces xml element’s value with the one provided as a command parameter \n\n\tUsage: $0 <xml filename> <element name> <new value>"
exit 127
fi
echo "DEBUG: Starting... [Ok]\n"
echo "DEBUG: searching $1 for tagname <$2> and replacing its value with '$3'"
temp_file="repl.temp"
echo " " >> $1
el_value=`grep "<$2>.*<.$2>" $1 | sed -e "s/^.*<$2/<$2/" | cut -f2 -d">"| cut -f1 -d"<"`
echo "DEBUG: Found the current value for the element <$2> - '$el_value'"
sed -e "s/<$2>$el_value<\/$2>/<$2>$3<\/$2>/g" $1 > $temp_file
chmod 666 $1
mv $temp_file $1
Is there a better way to do what I need to do? Can I do this in place and not use an intermediate file?
source
share