How to change the string in the file, but save the changes in another file, not original?

advertisements

I have a small problem. In my original.txt file I got some scheme with one variable zmuser to change. I'm using sed command to change my variable 'zmuser' to other string, which is also a variable.

sed -i -e s/zmuser/${user}/g original.txt

It changes the zmuser for my $user variable in original.txt.

How can I make changes from the file original.txt but save it in another .txt file?


This should do it:

sed -e "s/zmuser/${user}/g" original.txt > another.txt

How it works:

If you omit the -i flag from your sed command, the output will be printed on stdout. The > another.txt construct redirects that output to another.txt file.