mnanjala created the topic: String manipulation exercise
Hi Guys,
Say there is a text file inject.dat, it has 5 entries as below
PKGNAME=Project-debug
OLD_VERSION=1.0.0
NEW_VERSION=1.0.1
PRODUCT NUMBER=1
RELASE DATE=11/11/2011
How we could write shell script so I can read each line replace everything after “=”sign, with new value, example run
./inject.sh $PKGNAME $OLD_VERSION $NEW_VERSION $PRODUCT_NUMBER $RELEASE_DATE , so it should update the inject.dat with newer value what ever I give as parameter? Any idea?
Hint getopts.
rajeshkumar replied the topic: Re: String manipulation exercise
Hi praveen,
getopts is the best way to implement. I could not get much time to look into it. However, please find my quick code to implement the same. Please change the file name as needed. if time permits, tomorrow i will tell you more better way.
for line in $(< raj.txt)
do
if [ $# -eq 5 ]
then
case $line in
PKGNAME=$1) eval $line ;;
OLD_VERSION=$2) eval $line ;;
NEW_VERSION=$3) eval $line ;;
PRODUCT_NUMBER=$4) eval $line ;;
RELASE_DATE=$5) eval $line ;;
*) ;;
esac
fi
done
echo PKGNAME=$1 >> temp.txt
echo OLD_VERSION=$2 >> temp.txt
echo NEW_VERSION=$3 >> temp.txt
echo PRODUCT_NUMBER=$4 >> temp.txt
echo RELASE_DATE=$5 >> temp.txt
mv temp.txt raj2.txt
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024