Hello everyone,
How can I search a very large file, line by line for a string and if found print the entire line to another file.
Here is what I have, but it does not work very well for some reason.
Could you help.
I have a text file that looks like this.
202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more
any time I find a string with this ip address 202.142.152.20 I would like to print the entire line to another file.
#!/usr/bin/perl
open (INFILE, "< log_arc" or die "can not open file";
open (MYOUT, "> xresult.txt" ) or die "can not open file";
close MYOUT;
open (MYOUT, ">> xresult.txt" ) or die "can not open file";
while(<INFILE>)
{
# detect the domain controller.
if ( /202.142.152.20/)
{
chomp $_;
print MYOUT "$_ \n";
}
}
is this correct.
Thank you
How can I search a very large file, line by line for a string and if found print the entire line to another file.
Here is what I have, but it does not work very well for some reason.
Could you help.
I have a text file that looks like this.
202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more
202.142.152.20 some text some text and more and more202.142.152.20 some text some text and more and more
any time I find a string with this ip address 202.142.152.20 I would like to print the entire line to another file.
#!/usr/bin/perl
open (INFILE, "< log_arc" or die "can not open file";
open (MYOUT, "> xresult.txt" ) or die "can not open file";
close MYOUT;
open (MYOUT, ">> xresult.txt" ) or die "can not open file";
while(<INFILE>)
{
# detect the domain controller.
if ( /202.142.152.20/)
{
chomp $_;
print MYOUT "$_ \n";
}
}
is this correct.
Thank you