replaced variable field within shell script using sed
Hi
I have a file called myfile: contents as follows: /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/apps/m edsys/' -x 7 restore /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/apps/m edtst/' -x 7 restore /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/u1/med sys/wrk/' -x 7 restore /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/u1/prn tsys/' -x 7 restore /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/usr/pr ntsys/' -x 7 restore /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/usr/sy s_data/' -x 7 restore /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/usr/ut il/' -x 7 restore /usr/snapshot-efb/snapshot -i 10.3.15.25 -a '/mnt/i/a/a' -2 483326bf -3 '/backup /medsys/' -x 7 restore my problem is trying to amend the 7th field which is "483326bf" using this script: # Add the Tagnumber to change TAGNUM=`awk '/snap/ {print $7}' myfile` NEWTAGNUM=`awk '/snap/ {print $7}' myfile.out` echo "Enter the The Tag Number for Restore, or Q to quit if not required." echo "-->\c " read TAG case $TAG in q|Q) break ;; *) echo "Tag Number -->\c " echo $TAG >newfile echo $TAG >>newfile echo $TAG >>newfile echo $TAG >>newfile echo $TAG >>newfile echo $TAG >>newfile for FILE in `ls myfile` do sed -e 's/"$TAGNUM"/"$newfile"/g' myfile >myfile.out # sed -e 's!$TAGNUM!$newfile!g' myfile >myfile1 done esac I somehow cannot get the variable changed withing my script -If I manually replace $TAGNUM to 483326bf it works. Any help will be much appreciated thanks Hamim |
I'm not sure what exactly are you trying to do
but try this: Code:
#!/bin/bash also try Code:
#!/bin/bash |
works 100%
Thanks -It works
that is what i was looking for Hamim |
All times are GMT -5. The time now is 04:29 PM. |