Link to home
Start Free TrialLog in
Avatar of mansur_mca
mansur_mcaFlag for United Arab Emirates

asked on

how to built Batch script to scan for the particular word or phrase in flat file

dear experts ,
How to check in flat file though win -batch script that particular word  or phrase  exist.  
- This flat file used  as the input to the script and could be able to return the flag based on the  search.
- my requirement  very much similar functionality  that  "grep" command  do in UNIX environment .  

thanks all in advance ...
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

You can use find or findstr for this purpose.
As you're already familiar with it, you might want to install a windows version of grep from
http://gnuwin32.sourceforge.net/packages/grep.htm

You might need to update your path in order to get it to work:
Start -> Control Panel -> System,
"Advanced" tab
"Environment Variables" button
Select "Path" in System variables, "Edit" button, add semi-colon and directory of your grep installation to the end of the existing text.

if perl then use attached code.
open(IN);
my @file = <IN>;
close(IN);
 
my $word = 'test'; ## the word to search
 
my $lines_found = grep(m|$word|i, @file); ## number of lines found having word `test` inside the file.

Open in new window

Avatar of FishMonger
Perl would be overkill for this task, but if it was used, here's a more efficient 1 liner.
perl -ne "print if /some word or phrase/i" file.txt

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gastone Canali
Gastone Canali
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial