sed search and replace creating new file

To make your second example work, where you explicitly want to create a second file, simply drop the -i flag.

sed 's/<texttoreplace>/<newtext>/g' foo.txt > bar.txt

Your first example is a bit of a head-scratcher. The -i flag performs the editing in place, with an optional backup file of the original contents. It works fine for me, without the creation of a '.txte' file. You might get it to work by explicitly telling it no extension, using the syntax below:

sed -i'' 's/<texttoreplace>/<newtext>/g' foo.txt

You shouldn't have to do that, but maybe there is something in your environment different from mine.


just copy and do sed

# docker can not replace mount file
cp /etc/nginx/conf.d/nginx.template /etc/nginx/conf.d/nginx.conf
sed -i "s/findText/${replaceText}/g" /etc/nginx/conf.d/dboard_nginx.conf

Tags:

Cygwin

Sed