I am using RHEL 7.0 system. I have this boot.cfg file that has the following fields:

bootstate=0 title=Loading ESXi installer timeout=5 prefix= kernel=tboot.b00

kernelopt=runweasel formatwithmbr

How can I update this boot.cfg file's IP address?

I have earlier used the following script:


sed '/[kernel=tboot.b00]/a [prefix=]/' boot.cfg

I was trying to append the updated IP address using sed to the end of the "kernel..." field. but it didn't make any changes.

Secondly, how do I ensure that the changes to the IP address is saved and not temporary?

Thanks in advance


Input file

bootstate=0 title=Loading ESXi installer timeout=5 prefix= kernel=tboot.b00


sed -i  "s;kernel.*;&[prefix=];g" boot.cfg

After executing above command boot.cfg will be as below

bootstate=0 title=Loading ESXi installer timeout=5 prefix= kernel=tboot.b00[prefix=]
  • There was no effect on the boot.cfg. I am using the owner permissions of rwx but it still does not save the changes. Dec 8 '17 at 10:14
  • Use below command to get it saved permanently sed -i “s;kernel.*;&[prefix=];g" boot.cfg Dec 8 '17 at 10:39
  • Kumar : hi I received the following error when I tried your suggestion: sed: no input files ./<scriptname>: line 13: boot.cfg: command not found Dec 11 '17 at 3:00
  • @MightStackier i edited the code in answer Kindly check and update Dec 11 '17 at 17:12
  • Kumar: No errors and the file was updated permanently. It finally worked! Thank you! Dec 12 '17 at 1:38

ALright I found my own answer to the second question credit to http://brunolinux.com/02-The_Terminal/Find_and%20Replace_with_Sed.html

in order to fully replace/update the prefix field instead of appending an earlier field,"escape sign" ( \ ) is needed.The modified code is as follows:

sed -i 's;prefix.*;prefix=;g' boot.cfg

Appreciate the earlier help from kumar and the above mentioned website!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.