I have a file template.jou
that has the following format:
/codeline1
/codeline2
/var = var
/codeline3
Now I want to replace the var
part with different values like A
, B
and C
and then write the contents of template.jou
with the replaced value to a new file.
I tried the following:
sed -n 's/var/A/gpw A.jou' template.jou
But this only printed the pattern matched line (i.e. /var = A
) to the new file A.jou
where I want the full file like this:
/codeline1
/codeline2
/var = A
/codeline3
I've also tried:
sed -i '.bak' 's/var/A/g' template.jou
This replaced the template.jou file with new contents, but I want it to change filename as well such that the new file is called A.jou
.