I want to locate a string 'Local=IN' from a file and I am sure that this string is located within 100 lines(assumptio n) from the beginning of the file out of 5000 lines. The 100th line start with the word '--Begin'. So in order to locate the string from only 100 line, I think copying all the file content into any array is not a good idea.
I want the grep command to exist in the script.
I have the following code. I need this to be modified as per the above condition.
Your help will be appreciated.
Thanks
Find the string using grep command from the huge data file
I want the grep command to exist in the script.
I have the following code. I need this to be modified as per the above condition.
Your help will be appreciated.
Thanks
Code:
$fname="file.txt";
open(FH,$fname);
@file_content=<FH>;
foreach (@file_content){
my $match_text=grep {"Local=IN"},@file_content;
Last if($match_text);
else {
open(WH,"temp.log");
print WH "$\n";
if (/Testing Option 0 ok/){
print "Local=IN\n";
}
unlink($fname);
rename(temp.log,"$fname");
}
Find the string using grep command from the huge data file
Comment