【发布时间】:2017-04-06 09:10:24
【问题描述】:
我试图找出文件之间的差异,但文件名和目录名包含空格。我正在尝试在 Perl 脚本中执行命令。
diff /home/users/feroz/logs/back_up20161112/Security File/General Security.csv /home/users/feroz/logs/back_up20161113/Security File/General Security.csv
Perl
open( my $FH, '>', $logfile ) or die "Cannot open the file '$logfile' $!";
foreach $filename ( keys %filenames ) {
$old_file = $parent_directory . $previous_date . $search_directory . "$filenames{$filename}";
$new_file = $parent_directory . $current_date . $search_directory . "$filenames{$filename}";
if ( !-e $old_file ) {
#print ("\nFile does not exist in previos date backup");
print $FH "\nERROR:'$old_file' ---- does not exist in the backup directory ";
}
elsif ( !-e $new_file ) {
#print ("\n The file does not exist in current directory");
print $FH "\nERROR:'$new_file' --- does not exist in the present directory ";
}
else {
# print $FH "\nDifference between the files $filenames{$filename} of $previous_date and $current_date ";
my $cmd = 'diff $old_file $new_file| xargs -0';
open( my $OH, '|-', $cmd ) or die "Failed to read the output";
while ( <OH> ) {
print $FH "$_";
}
close $OH;
}
}
【问题讨论】:
-
diff不是 Perl 命令。请出示您的真实代码。 -
diff 不是 perl 命令。我正在尝试在 perl 脚本中执行 unix 命令。我提到了 perl 脚本来检查我们是否有任何选项来忽略空白
-
@ferozalam_82:这不相关。请出示您的真实 Perl 代码。
-
这是我的 perl 代码
-
我什至尝试过 unix 的选项 xargs 选项,我不知道它是否有效