why sed replace + redirection deletes my file?

前端 未结 3 1338
执笔经年
执笔经年 2021-01-13 06:57

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 /         


        
3条回答
  •  礼貌的吻别
    2021-01-13 07:04

    sed reads your files in as a stream and outputs a stream as well. As soon as you perform the redirection into your file the contents are overwritten, and since that file is being read as a stream, it hasn't even started being read by sed yet. When sed does start reading the file it is empty so it finishes immediately with no output.

    Use -i, to do an in-place edit, instead:

    sed 's/www-test/www/g' -i /home/websync/tmp/sitio-oficial/sitios/wp-config.php
    

提交回复
热议问题