Hi, I am looking at modifiying a file but getting a bit lost with what i am trying to do.
I have the following file i need to alter. I want to search a list of files for the DEVSERIAL "0007862454" part but only the numbers. I then need to replace the line under DRIVES with the correct drive path.
NAME "Drive Name"
DESCRIPTION ""
HOST Host Name
POLICY SCSI-II
TYPE LTO-Ultrium
POOL "Default LTO-Ultrium"
LIBRARY "Library Name"
CLEANME
BUFFERS 32
DRIVES
"/dev/rmt/s99mn"
"49"
BLKSIZE 256
LOCKNAME "Lock Name"
SANSTABLEADDR
DEVSERIAL "0007862454"
DEVICESUBTYPE ""
RESTOREDEVICEPOOL NO
COPYDEVICEPOOL NO
This is the script that i currently trying to play with but dont seem to be getting anywhere. I am i anywhere near the ball park on what i want to do or miles away.
for i in `drive_list`
do
echo "Editing $i"
awk '{ if ( $0 ~ /0007862454/ ) {
printf( "%s\n%s\n", "Some new inserted text here", $0 );
# could use the following to append
# printf( "%s\n%s\n", $0, "Some new appended text here" );
} else {
print $0;
}
}' drive_list
done
I have done one script for replacing all sysouts from my project. It may help you.
It will:
Print before how was it
Replace the needed Word alone
Print after how it is.
Print no of files changed
P.S : As sed -ie is used , a backup file with extension e will be created. So I wrote code to delete that too. I think sed -i only has to use. Anyway this script worked perfectly for me.
Take a backup of entire folder you wanna change. There is no guarantee from me.
I know this is not the right thing you asked.
Change what ever you need to.
I have now got that command working via command line perfectly. I just need to sort out the rest so that it uses variable to bring in the changes. Thank you for your help.
Now i understand the need to for the -v which is to allow in the variables. You just answered the question i was going to ask.
Been a great help. Spend many hours trying to work this out. So simple when you know how.