Created
February 3, 2015 14:44
-
-
Save icheernoom/c794b4901771c377e676 to your computer and use it in GitHub Desktop.
Search String in Files on Directory and Subdirectory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use File::Find; | |
print "\n\n\t### Search String in Files on Directory and Subdirectory By ICheer_No0M ###\n\n"; | |
print 'Path File : '; | |
chomp($path=<stdin>); | |
print 'Search Keyword : '; | |
chomp($string=<stdin>); | |
$keyword = AddSlashes($string); | |
find(\&file_names, $path); | |
sub file_names { | |
if($_ =~ /\.php$/){ | |
$file = $File::Find::name; | |
open (MYFILE, $file); | |
$line = 1; | |
while (<MYFILE>) { | |
$content .= $_; | |
if($content=~/$keyword/){ | |
print "\nFound : $string\n"; | |
print "On Line : $line\n"; | |
print "On File : $file\n"; | |
} | |
$line += 1; | |
$content = ""; | |
} | |
close (MYFILE); | |
} | |
} | |
print "\n\n\t### Finding $string on $path Complete... ###\n\n"; | |
sub AddSlashes { | |
$text = $_[0]; | |
$text =~ s/\\/\\\\/g; | |
$text =~ s/\$/\\\$/g; | |
$text =~ s/\'/\\'/g; | |
$text =~ s/\"/\\\"/g; | |
$text =~ s/\[/\\[/g; | |
$text =~ s/\]/\\\]/g; | |
$text =~ s/\(/\\(/g; | |
$text =~ s/\)/\\\)/g; | |
$text =~ s/\\0/\\\\0/g; | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment