Shell - replace a string in a specific place of a text file

Hi,

Im trying to figure out what would be the sed command to replace three strings in a the text file below...

This is the text file:
# cat /etc/udev/rules.d/99-oracle-asmdevices.rules
KERNEL=="sd?", BUS=="scsi", PROGRAM="/sbin/scsi_id -g -u -s %p",
RESULT=="36345c296acf83a81f363fbcb76421f5e", NAME="oracleasm/DATA01",
OWNER="oracle", GROUP="oinstall", MODE="0660"
KERNEL=="sd?", BUS=="scsi", PROGRAM="/sbin/scsi_id -g -u -s %p",
RESULT=="36222c294f721eca61b285845ad38e3a6", NAME="oracleasm/REDO01",
OWNER="oracle", GROUP="oinstall", MODE="0660"
KERNEL=="sd?", BUS=="scsi", PROGRAM="/sbin/scsi_id -g -u -s %p",
RESULT=="36333c2985d477b0ef471b75fe06c59a8", NAME="oracleasm/ARCH01",
OWNER="oracle", GROUP="oinstall", MODE="0660"

I have these three inputs into variables:
sdb_scsi=$(scsi_id -g -u -s /block/sdb)
sdb_scsi=$(scsi_id -g -u -s /block/sdc)
sdb_scsi=$(scsi_id -g -u -s /block/sdd)

These commands will give me:
# scsi_id -g -u -s /block/sdb
36000c296acf83a81f363fbcb76421f5e
# scsi_id -g -u -s /block/sdc
36000c294f721eca61b285845ad38e3a6
# scsi_id -g -u -s /block/sdd
36000c2985d477b0ef471b75fe06c59a8

How can I replace the big string in the text file above for these ones in the right order? So the text file can become:

# cat /etc/udev/rules.d/99-oracle-asmdevices.rules
KERNEL=="sd?", BUS=="scsi", PROGRAM="/sbin/scsi_id -g -u -s %p",
RESULT=="36000c296acf83a81f363fbcb76421f5e", NAME="oracleasm/DATA01",
OWNER="oracle", GROUP="oinstall", MODE="0660"
KERNEL=="sd?", BUS=="scsi", PROGRAM="/sbin/scsi_id -g -u -s %p",
RESULT=="36000c294f721eca61b285845ad38e3a6", NAME="oracleasm/REDO01",
OWNER="oracle", GROUP="oinstall", MODE="0660"
KERNEL=="sd?", BUS=="scsi", PROGRAM="/sbin/scsi_id -g -u -s %p",
RESULT=="36000c2985d477b0ef471b75fe06c59a8", NAME="oracleasm/ARCH01",
OWNER="oracle", GROUP="oinstall", MODE="0660"

NOTES:
1- The strings to be replaced in the text file may not have the value I put here.. it can vary..
2- The values as output of the command can vary as well...
3- The length of the strings (both in the file and in the command output is the same)

=====

I was thinking in running the first command, replace the value in the first RESULT=="" of the file, then run the second command and replace it again until the third coomand/replace..

Not sure if its the best way to go...

Tks,
Joao
joaotellesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
How do you decide which RESULT is replaced by which scsi_id -g -u -s ?

Does DATA01 always correspond to sdb, REDO01 to sdc, and ARCH01 to sdd?
joaotellesAuthor Commented:
Thats correct.

DATA01 always correspond to sdb, REDO01 to sdc, and ARCH01 to sdd.
ozoCommented:
sed -i.bak -e 's#.*/DATA01"#RESULT=="'$sdb_scsi'", NAME="oracleasm/DATA01"#' -e 's#.*/REDO01"#RESULT=="'$sdc_scsi'", NAME="oracleasm/REDO01"#' -e 's#.*/ARCH01"#RESULT=="'$sdd_scsi'", NAME="oracleasm/ARCH01"#' 99-oracle-asmdevices.rules.in

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joaotellesAuthor Commented:
Tks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.