perl - Sed错误 "sed: no input files"

标签 perl sed command-line-arguments

我有一个脚本可以清理作为参数提供的文件中的模式。

需要清理的“file1”和脚本位于同一位置。当我将“file1”作为参数传递时,回显良好,但在 执行 sed 命令时出现以下错误:

-sh-3.2$ ./temp.pl file1.txt

File provided as the argument : file1.txt
sed: no input files

我的脚本是:

my $logfile = $ARGV[0];
print "File provided as the argument : $logfile \n";
$cmd = q(sed -i '/Job will shutdown./d' $logfile);
$n = system($cmd);

最佳答案

更改您的报价系统:

$cmd = "sed -i '/Job will shutdown./d' $logfile";

或者:

$cmd = qq(sed -i '/Job will shutdown./d' $logfile);

检查http://www.perlmonks.org/?node=quotes+in+Perl

PD:此任务可以在 perl 中本地完成。

关于perl - Sed错误 "sed: no input files",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29599798/

相关文章:

linux - 使用 sed 重命名多个文件

c# - 执行 System.Diagnostics.Process cmd.exe 仅打开命令提示符,不执行参数

perl - 如何从 Perl 中的 CSV 文件中提取字段?

php - 如何在Linux服务器使用率最低(繁忙)的情况下用PHP备份一个巨大的mysql数据库?

bash - sed 不写入文件

shell - 在 shell 中覆盖原始文件中的一行

c++ - 多个 WT 应用程序可以在同一个端口上运行吗?

java - 在 Java 程序的命令行中使用 *

perl - 如何访问 HTTP::Server::Simple::CGI 中的 HTTP 请求 header ?

perl - 为什么只有其中一个告诉我 "Modification of a read-only value attempted"?