简体   繁体   English

问题使用sed修改文件

[英]Problems modify files with sed

I have a problem with the following code, if I make the 1.log file but does not modify the files containing PHP eval (..). 如果我制作1.log文件但不修改包含PHP eval(..)的文件,则以下代码有问题。 shows me the following: sed: no input files. 显示以下内容: sed: no input files.

In that I'm wrong? 那我错了吗?

grep -lr --include=*.php "eval(base64_decode" ./ >> 1.log | xargs sed -i.bak 's/<?php eval(base64_decode[^;]*;/<?php\n/g'

You get the error message because your grep command does not produce any output (which you pass to sed via xargs). 您收到错误消息,因为您的grep命令不产生任何输出(您通过xargs传递给sed)。 You probably wanted this: 您可能想要这样:

grep -lr --include=*.php "eval(base64_decode" ./ | xargs sed -i.bak 's/<?php eval(base64_decode[^;]*;/<?php\n/g'

Alternative with a file list: 替代文件列表:

grep -lr --include=*.php "eval(base64_decode" ./ > files
sed -i.bak 's/<?php eval(base64_decode[^;]*;/<?php\n/g' $(cat files)

If you want to save the output in the log file and also pipe it to xargs , use tee : 如果要将输出保存到日志文件中,并将其通过管道传输到xargs ,请使用tee

grep -lr --include=*.php "eval(base64_decode" ./ |
    tee -a 1.log |
    xargs sed -i.bak 's/<?php eval(base64_decode[^;]*;/<?php\n/g'

The -a option makes tee append to the file. -a选项使tee附加到文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM