#!/usr/bin/perl #-------------------------------------------------------------------- #By: Keven Murphy #Date: 01/10/2007 # #License: GPL v2.0 # #Description: Will search a given file for a list of keywords from a #file. The search is case insenstive and will put each keyword it #finds into its own file. # #Options: # --file {file} The file you want to search # --wordfile {file} The file that contains your keywords # --output {directory path} Where you want the output files to be # created. Note you need to create the # directory before hand. # #Example: ./word_search.pl --file image.dd.unallocated.ascii # --wordfile keyword.txt --output /case/100/keyword #-------------------------------------------------------------------- use Getopt::Long; sub FindWord{ foreach $word (@wordlist){ chomp ($_); #print "line: $_\n"; if ($_ =~ m/$word/ig) { #print "Found\n"; print $word "$_\n"; } } } GetOptions("verbose!"=>\$opt{verbose}, "wordfile=s"=>\$opt{wordfile}, "output=s"=>\$opt{output}, "file=s"=>\$opt{file}); open (WORDFILE, "<$opt{wordfile}") || die ("Could not open $opt{wordfile} file."); $cnt=0; while () { chomp ($_); print "$_\n"; $wordlist[$cnt] = $_; $cnt++; } close(WORDFILE); foreach $word (@wordlist) { print "Creating save file: $word\n"; open ($word, ">$opt{output}/$word") || die ("Could not open $word file."); } open (SFILE, "<$opt{file}") || die ("Could not open $opt{file} file."); while () { FindWord; } close(WORDFILE); foreach $word (@wordlist) { close ($word); }