🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started 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

Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x