Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

String manipulation exercise

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

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x