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/

相关文章:

multithreading - 如何在 Perl 线程中使用数组引用?

mysql - 编译 Perl 的 DBD::mysql 时如何修复 "Symbol not found: _is_prefix"?

linux - 尝试获取 token 时 Xero Partner API Oauth 证书问题 (Linux/Perl)

python - 如何从 cmd 读取 python 模块的文档字符串/帮助?

c# - 在 C# 中处理命令行选项的最佳方式

如果 1 个表不存在,则使用 mysqldump 创建数据库

perl - 用于安装 Perl 模块的 Elastic MapReduce Bootstrap

regex - 使用 sed 打印每个匹配模式的第一行出现次数

sed - 如何自动创建目录树列表的 README.md markdown

linux - sed 未按预期工作,但仅适用于目录深度大于 1