How To replace a line with multiple lines in a text file


I have below line in multiple files

module load ibmdb2/client/10.1.3

I want to replace this line with below 3 lines.

DB_Ver=`grep -w 'DB_Version' $INFA_CONFIG | cut -d '=' -f 2`
module load ibmdb2/client/$DB_Ver

Can you please help on this ?

Try the following syntax:

sed -e 's+module load ibmdb2/client/10.1.3+INFA_CONFIG="$HOME/config/research_dw_rt_$ENV_VAR.cfg"\nDB_Ver=`grep -w 'DB_Version' $INFA_CONFIG | cut -d '=' -f 2`\n&+g'

The \n will add a new line as per your needs and the filnal & will replace the search string module load ibmdb2/client/10.1.3.

See How to use sed to find and replace text in files in Linux / Unix shell

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki