in reply to need helpo regarding regular expression
here is my whole script
###################################################################### +########### # this program will search the string in that +# # are present in the whole directory structure. + # # Pass command line arguments as follows---- + # # perl removestring.pl path Searchstring + # ###################################################################### +########### #!/usr/bin/perl use strict; use File::Find; use warnings; my $oldstring; my $newstring; my $path; my $i=0; sub checkArgs() { print $#ARGV+1; die "invalid no of arguments [path oldstring new string]!!" if $#ARGV ++1 !=2 ; for ( @ARGV ) { s/\\n/\n/g; } $oldstring="$ARGV[1]"; print "<<$oldstring>>\n"; $path=$ARGV[0]; print "path: $path ,string:$oldstring(y/n):"; my $ok=<STDIN>; chomp($ok); die "please run the program again with correct arguments:!!" if $ok n +e "y"; find(\&wanted,$path); print "\n\nString Found in $i Files"; } sub wanted { my $flag=0; $flag=1 if !-d && $File::Find::name =~ /.bteq$/; if($flag==1){ my $string=""; open FH1, "< $File::Find::name" or die "Couldn't open file: " +; while (<FH1>){ $string .= $_; } if($string=~ m/\Q$oldstring\E/){ print "\nstring found in ...\n$File::Find::name"; $i++; } } } checkArgs();
this is my file
SELECT JSON_col FROM stud_info_small ORDER BY JSON_col.stu_id; SELECT JSON_col FROM stud_info_small WHERE JSON_col.stu_id = "stu_10" ORDER BY JSON_col.stu_id; SELECT JSON_col FROM stud_info_small WHERE JSON_col.qualifications = "Associate Degree" ORDER BY JSON_col.stu_id; ORDER BY stud_doc.stud_id; ORDER BY stud_doc.stud_id;
arguments-- perl search.pl E:\foldername "stud_doc.su_id"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: need helpo regarding regular expression
by davido (Cardinal) on Nov 27, 2014 at 09:32 UTC |