|
Answer» I have a file which contains MULTIPLE repeated data, some of which is expected and has a tag (Field 1, etc)but due to circumstances outside my control it also has occassional (29 from 200k, not MANY but ENOUGH to cause havoc!) rogue data e.g.:
Field 1: Field 2: Field 3: dross.rogue.variable.data.dross
Field 1: Field 2: Field 3:
I need to create a file containing just Field 1 and Field 2. Before the bad data records came to light, findstr /v "Field 3:" extract1.txt > extract2.txt was doing the job well. But this won't remove the dross. I THOUGHT it must be possible to reverse the logic and rather than delete the unwanted records just copy the required ones but can't find a command to do so. This is on an NT 2003 server. Anyone got any SUGGESTIONS? Thanks. Using the FOR command..
Start of code:
FOR /F "delims=" %%I in (data.txt) do (
FOR %%J in (%%I) do (
echo %%J>tmp1.txt find /i "gross" "tmp1.txt >nul if not errorlevel=1 echo %%J>>output.txt ) ) End of code
The First FOR command will load entire lines into memmory. The second for command will break the lines into single words. We then write the current variable into a text file, and do a find on it. Were are only interrested in the errorlevel output. Errorlevel 1 is bad. anything else is okay. The output is formatted into a single colum text file.
|