I have two files. First (goodlist.txt) is just a list of words, one per line, against which I wish to validate. Second (checkme.csv) is a CSV text file, with one "column" (e.g., the word between the 2nd and 3rd commas) containing a word I wish to ensure is found within the other file, the definitive list of allowable words.
If the csv file is OK, do one thing (nothing, or a message, or move the csv to a GoodFiles folder). If any line in the csv contains a word between the 2nd and 3rd commas that is not found in the reference file, do something else (a message, error file, beep, move csv to BadFiles folder...) that indicates the line number on which the erroneous code word was found, and the erroneous code word itself.
I'm hoping I don't have to pull out the big guns and move up to VB or such. Thanks for any help!
Confirm each item in one file is found in another
Moderator: DosItHelp
Re: Confirm each item in one file is found in another
Untested code:
The code assumes that columns 1 and 2 are never empty - if they are then the code requires a major rewrite.
Adjustments will need to be made if either file contains special characters, quotes or leading or trailing spaces.
The search can be made case insensitive by adding the /I option to the FINDSTR command.
Dave Benham
Code: Select all
@echo off
setlocal
set goodFile="goodlist.txt"
set checkFile="checkme.csv"
set badFile="badWords.txt"
if exist %badFile% del %badFile%
for /f "usebackq eol=, tokens=3 delims=," %%a in (%checkFile%) do (
echo %%a|findstr /vx /g:%goodFile% >>%badFile%
)
if exist %badfile% (
echo %checkFile% is BAD
echo The following words in column 3 failed:
type %badFile%
) else (
echo %checkFile% is GOOD
)
The code assumes that columns 1 and 2 are never empty - if they are then the code requires a major rewrite.
Adjustments will need to be made if either file contains special characters, quotes or leading or trailing spaces.
The search can be made case insensitive by adding the /I option to the FINDSTR command.
Dave Benham