Benomar yacine Benomar yacine - 3 months ago 9
Bash Question

Linux script to insert in a file a new line

I have a problem I am trying to write a script that will allowed me to write on a conf file for so i was trying to use a sed command but it looks like it works but doesn't save it in the file so my script is

sed '/# Load Java configuration/i JBOSS_User=root' ITg.conf


this should add "JBOSS_User=root" after the line "# Load Java configuration"

How can I do it?

Answer

try this;

sed -i '/# Load Java configuration/i JBOSS_User=root'  ITg.conf

before this command, make backup as below;

cp ITg.conf ITg.conf_backup

man sed :

-i[SUFFIX], --in-place[=SUFFIX]

              edit files in place (makes backup if SUFFIX supplied)
Comments