Thursday, November 30, 2017

Sed replace a text with a variable of output of command

Sometimes we need to replace a string with a variable or output of a Linux command we can use Sed in following way to do that

sed -i "s/textTOreplace/${variablename}/g" /file_path

If you also want a backup of the original file to be created after replacement that you can use .bak after -i parameter as follows:

sed -i.bak "s/textTOreplace/${variablename}/g" /file_path





No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...