perl - Search a list file of files for keywords -


i have array of files. need cat each file , search list of keywords in file keywords.txt.

my keywords.txt contains below

aes 3des md5 des sha-1 sha-256 sha-512 10.* http:// www. @john.com john.com 

and i'm expecting output below

file jack.txt contains aes:5 (5 line number) http://:55 file new.txt contains 3des:75 http://:105 

okay here code

use warnings;  use strict;   open stdout, '>>', "my_stdout_file.txt";    $filename = $argv[2];   chomp ($filename);   open $fh, q[<], shift or die $!;     %keyword = map { chomp; $_ => 1 } <$fh>;    print "$fh\n";    while ( <> ) {     chomp;     @words = split;     ( $i = 0; $i <= $#words; $i++ ) {         if ( $keyword{ $words[ $i ] } ) {                 print "keyword found file:$filename\n";                 printf qq[$filename line: %4d\tword position:         %4d\tkeyword: %s\n],                         $., $i, $words[ $i ];         } } } 

but problem considering arguments , trying open files argv[2]. need open argv[0] , argv[1]. argv[2] kept writing in output only. appreciate responses. thanks.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -