linux - 使用sed处理find命令查找到的文件并将处理结果输出到该文件, 最后文件内容会被清空的问题
伊谢尔伦
伊谢尔伦 2017-04-17 16:15:36
0
1
405

使用如下代码来处理文件

find "src" -type f -iname "*.log" | xargs -I{} sed -n -e $default"p; w {}" {};

我期待的结果是, 对所有src目录下的*.log文件里面的内容进行处理, 并且将处理的结果输出到源文件里面。
然而执行完之后, 所有匹配的文件内容都会被清空。

如果我只输出不重写文件的话的话, 输出是自己期待的, 如以下命令

find "src" -type f -iname "*.log" | xargs -I{} sed -n -e $default"p;" {};

使用-exec而不是管道的话, 也是一样的

find "src" -type f -iname "*.log" -exec sed -n -e $default"p; w {}" {} \;

那我是哪里出了问题了呢???

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
刘奇

You can use the sed option in your second command-ito modify the source file directly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!