system(“grep \”^ 2013 / $ yesterday- \“Log_2013_ $ yesterday * .txt> Log_2013_ $ yesterday.txt”);
我无法运行具有上述代码的perl脚本。它在linux上工作正常。我认为问题是窗口上的perl没有grep命令。所以任何人都可以帮我重写这个,所以它将在窗口上工作。
我在想使用findstr
谢谢,
答案 0 :(得分:0)
在Perl中重新实现grep
,然后使用system
调用新的grep
命令:
# create a new perl script called "grep" in current directory
# put this near the beginning of your script
open GREP, ">grep";
print GREP <<'EOF';
#! perl
$regex = $ARGV[0];
while (<STDIN>) {
print if $_ =~ $regex;
}
EOF
$yesterday = ...;
system("perl grep \"^2013/$yesterday-\" Log_2013_$yesterday*.txt > Log_2013_$yesterday.txt");
# note that you have to say system("perl grep ...") now
# and not just system('grep ...")