I want to find a string say 'foo' in a file sat '1.txt' using shell script and replace 'foo' with 'bar' and store the output into other file say '2.txt' without any modification in 1.txt.
so '1.txt' would contain 'foo' itself but '2.txt' will now have all the contents of '1.txt' with 'foo' replaced by 'bar'
I am using this command in bash
sed -i "s/foo/bar/g" "1.txt" > 2.txt
but its not working.