I have two files
- input.txt
- keyword.txt
input.txt
has contents like:
.src_ref 0 "call.s" 24 first
0x000000 0x5a80 0x0060 BRA.l 0x60
.src_ref 0 "call.s" 30 first
0x000002 0x1bc5 RETI
.src_ref 0 "call.s" 31 first
0x000003 0x6840 MOV R0L,R0L
.src_ref 0 "call.s" 35 first
0x000004 0x1bc5 RETI
keyword.txt
has contents like:
MOV
BRA.l
RETI
ADD
SUB
..
etc
Now I want to read this keyword.txt
file and search it in input.txt
file and find how many times MOV
has occurred
how many times BRA.l
has occurred.
So far I have managed to get it working from a single file itself. here is the code
#!/usr/bin/perl
use strict;
use warnings;
sub retriver();
my @lines;
my $lines_ref;
my $count;
$lines_ref=retriver();
@lines=@$lines_ref;
$count=@lines;
print "Count :$count\nLines\n";
print join "\n",@lines;
sub retriver()
{
my $file='C:\Users\vk41286\Desktop\input.txt';
open FILE, $file or die "FILE $file NOT FOUND - $!\n";
my @contents=<FILE>;
my @filtered=grep(/MOV R0L,R0L/,@contents);
return \@filtered;
}
Here I can search only MOV
and I am unable to search other instructions like RETI
.
Also I want to put MOV,RETI
etc. in a keyword.txt
file and make it generic.
OUTPUT should be:
MOV has occured 2 times
RETI has occured 1 time