use strict; use warnings; # Open the files specified in @AGV $ARGV[0] or die "ERROR: No file for 114 lines"; $ARGV[1] or die "ERROR: No file for 300K lines";$ARGV[2] or die "ERROR +: No Output file name"; open my $smallfile,"<",$ARGV[0] or die "ERROR: COuld not open small fi +le $ARGV[0]:$!"; open my $bigfile,"<",$ARGV[1] or die "ERROR: COuld not open large file + $ARGV[1]:$!"; open my $outfile,">",$ARGV[2] or die "ERROR: COuld not open output fil +e $ARGV[2]:$!"; my $search_expression = ""; while(<$smallfile>){ chomp; next unless length; # skip if empty $search_expression .="\Q$_\E|"; } close $smallfile; chop $search_expression; # Delete extra "|" $search_expression = qr($search_expression); my $found_lines = 0; #Perform the search while (<$bigfile>){ next unless m/$search_expression/; # We have a matching line print $outfile $_; $found_lines++; } close $bigfile; close $outfile; print "Created $found_lines lines of output in $ARGV[2]\n";
We're living in a golden age. All you need is gold. -- D.W. Robertson.
In reply to Re: searching in large file
by NetWallah
in thread searching in large file
by sabas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |