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
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND