in reply to Re^5: Error using grep
in thread Error using grep
NOTE: This can be run as script.pl randomfile randomkey format#!/usr/bin/perl use strict; use warnings; if ($#ARGV != 1) { print "Error: Usage- script.pl filename keyword(to be searched)\neg:se +arch.pl config_file XYZ\n"; exit; } our $file=$ARGV[0]; our $key=$ARGV[1]; my $count = 0; if (-e "$file") { open (DATA,$file); chomp($key); # Search for the key pattern in the file information. while (defined (my $line = <DATA>)) { if ($line =~ /\b\Q$key\E\b/i) { #next; print "$line\n"; $count++; } } if($count == 0) { print "Keyword not found\n Search Completed\n"; } close (DATA); } else { print "Error: file does'nt exist\n"; exit; }
|
|---|