mansur_mca
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 ...
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 ...
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.
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.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.