-2

これは、ARGV[0] に到着するファイルを読み取り、一度に 1 行ずつ読み取り、その行をファイルの部分名として使用するコードです。ファイルの場所は不明であるため、find を使用してファイルの場所を見つけます。ファイルが存在する場合は、2 番目のパラメーター 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
4

2 に答える 2