Paul Massey - 2008-06-03

I am trying to write a batch file that passes the data once but gives me two output files from the original input file.

I tried doing this with a basic batch file but it chokes if the input file is very large.  I usually process files with over 500,000 lines (records).

[code]@echo off
setlocal enabledelayedexpansion
Set _WL=search.txt
Set _OF0=Profanity.txt
Set _OF1=Not_Profanity.txt
Set _SF=file 1.txt
If EXIST %_OF0% del %_OF0%
If EXIST %_OF1% del %_OF1%
For /f "usebackq tokens=*" %%a In ("%_SF%") Do (
  echo.%%a|findstr /g:"%_WL%">nul
  If !errorlevel!==0 (echo.%%a>>%_OF0%) else echo.%%a>>%_OF1%

So I thought maybe I could do this with the existing UnixUtils but I can't figure out how to use grep and get the matches to one file and the non matches to another file while only passing the data once.  Sure I could just run the grep twice and do a reverse match but when you are parsing millions of records that takes too much time that I don't have.

If this was a true bash script I could do something like this.

while read line
   if echo $line | grep -f search_strings.txt; then
       echo $line >> out1.txt
       echo $line >> out2.txt
done < file.txt[/code]

Anyone got any ideas how I could do this with UnixUtils in a batch file.  Can't use the included shell to do this.