I am using sed to search and replace two strings in a file in bash (GNU sed)
This is the file after
-rw-r--r-- 1 websync www-data 4156 mar 27 12:56 /home/websync/tmp/sitio-oficial/sitios/wp-config.php
here is the command I run
sed 's/www-test/www/g' /home/websync/tmp/sitio-oficial/sitios/wp-config.php > /home/websync/tmp/sitio-oficial/sitios/wp-config.php
and the result
-rw-r--r-- 1 websync www-data 0 mar 27 13:05 /home/websync/tmp/sitio-oficial/sitios/wp-config.php
EDIT: If I don’t redirect sed’s output, then I got the correct output. If I redirect to a new file, all works ok.
This is normal. you can’t read and write to the same file in a pipeline like this. (this will fail with other utilities than sed).
Use the in-place flag
-iinstead: