这是我读取到达 ARGV[0] 的文件并一次读取一行并将该行用作文件的部分名称的代码,该文件的位置未知,因此使用查找来查找如果存在文件,则将第二个参数 ARGV[1] 应用于该文件上的 grep。
if ($#ARGV != 1)
{
print "Usage : splfind.pl fullpath_of_input_file_contains_partial_filesnames_to_search pattern_to_search_on_filename_matched_file";
exit 1;
}
my $partfilelist_file=$ARGV[0];
my $stringtosearch=$ARGV[1];
my @partfilelist = split /\n/, `cat $partfilelist_file`;
while (defined ($partfileentry = pop(@partfilelist)))
{
print "===============================================================================\n";
#print "Searching for file with partial name $partfileentry as [find . -type f -name '*$partfileentry*.c']\n";
my $foundfile = `find . -type f -name '*$partfileentry*.c'`;
if ($foundfile)
{
print "Found file $foundfile\n";
system ("grep $stringtosearch $foundfile");
}
else
{
print "No file is found...\n";
}
}
我现在得到的输出
[rajeguna@ukstbuild3 suites]$ splfind.pl ~/ipclient-test.txt SEARCH_
===============================================================================
*.c']find . -type f -name '*DMS_1319_4MS_1319_4
No file is found...
===============================================================================
*.c']find . -type f -name '*DMS_1319_3MS_1319_3
No file is found...
===============================================================================
*.c']find . -type f -name '*DMS_1288_1MS_1288_1
No file is found...
===============================================================================
*.c']find . -type f -name '*DMS_1283_1MS_1283_1
No file is found...
===============================================================================
*.c']find . -type f -name '*DMS_1282_2MS_1282_2
No file is found...
===============================================================================
*.c']find . -type f -name '*DMS_1282_1MS_1282_1
No file is found...
===============================================================================
我的输入文件包含这个
DMS_0307_6
DMS_0307_7
DMS_0392_1
DMS_0393_1
DMS_0397_10
DMS_0397_6
DMS_0397_7
DMS_0397_8
DMS_0397_9
DMS_0549_20
DMS_0549_22