why sed replace + redirection deletes my file?

前端 未结 3 1357
执笔经年
执笔经年 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 07:08

    The redirection opens the file for output, truncating it. This happens simultaneously to sed opening it for reading, so sed sees the truncated version. You should redirect your output to a different file to avoid clobbering your input, or use sed's in-place editing mode instead of using redirection:

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

提交回复
热议问题