Replacing a line in a file

Hi all,

I need to replace a line

export TZ=xxxxxxxx

with the line

export TZ=$1

Now, "xxxxxxxx" in the above line is some unknown string and $1 is a parameter. I want the content of $1 to be replaced with "xxxxxxxx".

Kindly help me how to do this in the shell scripting.

sed -i "s/export TZ=xxxxxxxx/export TZ=$1/" file

I think the following line could help you

Shell script to find and replace string in multiple files - The UNIX and Linux Forums

Hi Balajesuri,

The "xxxxxxxx" is an unknown string. It could be "abcd" or "xyz" etc. I mentioned "xxxxxx" to indicate unknown string. So I can't search for this string.

Now, say $1= "mnopqr".
If I say "export TZ=$1" in the field for line to be replaced with in the sed command, will it write "export TZ=$1" or "export TZ=mnopqr".

I'd want it to be replaced with "mnopqr" and not $1.

sed -i "s/export TZ=[^ ]*/export TZ=$1/" file

Hi Balajesuri,

This works well. Thanks :b::slight_smile: