Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bash shell scripting problem

Status
Not open for further replies.

ady2k

Vendor
Jan 28, 2002
463
0
0
ID
The file (test.cfg) below here:
[TEST ITEMS]
Number Of Items = 2
Item 1 = /data/run-nov.csh,13
Item 2 = /data/run-dec.csh,14

I should change item 1 = /data/run-dec.csh,14 and item 2 = /data/run-jan.csh,3 on December

The test.sh below here :

#!/bin/sh

printf "Enter current month (mmm):"
read curmth
printf "Enter next month (mmm):"
read appmth
printf "Enter number of month for item1:"
read inumber1
printf "Enter number of month for item2:"
read inumber2

item1=`cat db/test.cfg | head -3 | tail -1 | cut -c 40-49`
item2= `cat db/preload1.ini | tail -1 | cut -c 40-49`

newitem1="$curmth.csh,$inumber1"
cmd17="sed -e 's/$item1/$newitem1/g' db/test.cfg > db/test.cfg.1"
eval $cmd17
mv -f db/test.cfg.1 db/test1.cfg

newitem2="$appmth.csh,$inumber2"
cmd18="sed -e 's/$item2/$newitem2/g' db/test1.cfg > db/test.cfg.2"
eval $cmd17
mv -f db/test.cfg.2 db/test.cfg
--------------------------------------------------
But I got the output (test.cfg) with input: curmth = dec, appmth = jan, inumber1 = 14 and inumber2 = 3 below :
[TEST ITEMS]
Number Of Items = 2
Item 1 = /data/run-dec.csh,14
Item 2 = /data/run-dec.csh,14

Anyone can help me ?

The expected result (test.cfg) should be like below here :
[TEST ITEMS]
Number Of Items = 2
Item 1 = /data/run-dec.csh,14
Item 2 = /data/run-jan.csh,3

Thanks
 
not sure if this is it or not, but
in newitem2 cmd18, you are running sed on the same dbfile. which is most likely ok, but then you eval $cmd17 again and not $cmd18.

>---------------------------------------Lawrence Feldman
SR. QA. Engineer SNAP Appliance
lfeldman@snapappliance.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top