为什么SED替代+重定向删除我的档案? [英] why sed replace + redirection deletes my file?

查看:195
本文介绍了为什么SED替代+重定向删除我的档案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SED搜索和在bash文件替换两个字符串(GNU SED)

I am using sed to search and replace two strings in a file in bash (GNU sed)

这是该文件后,

-rw-r--r-- 1 websync www-data 4156 mar 27 12:56 /home/websync/tmp/sitio-oficial/sitios/wp-config.php

下面是我运行命令

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

和结果

-rw-r--r-- 1 websync www-data 0 mar 27 13:05 /home/websync/tmp/sitio-oficial/sitios/wp-config.php

编辑:如果我不重定向的sed的输出,然后我得到了正确的输出。如果我重定向到一个新的文件,一切工作正常。

If I don't redirect sed's output, then I got the correct output. If I redirect to a new file, all works ok.

推荐答案

这是正常的。您无法读取和写入相同的文件在这样的管道。 (这将失败,其他公用事业比SED)。

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).

使用就地标志 -i 而不是:

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

这篇关于为什么SED替代+重定向删除我的档案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆