Read CSV for variable and check the cells on that line for another variable
I am trying to create a batch file to read a CSV file to find a username that will be a variable then check the next 10 cells on that line if they match another variable which will be a number.
Example CSV:
bsmith, 22, 14, 15, 12, 18, 19
cwright, 10, 15, 11, 2
hwrong, 2, 6, 3
csmith, 10, 16, 19, 3, 5, 19, 18, 7, 2, 4
any help would be greatly appreciated! Thanks
I have this to find the username but now I want to check the numbers if they match another variable:
Variables are: 'username' and 'sitenum'
findstr /c:"%username%" "ACL.csv" >nul 2>&1
IF NOT ERRORLEVEL 1 (
echo AUTHORIZED
) else (
echo UNATHORIZED!!!!
)
I want to check the numbers if they match another variable
Just pipe (|
) the output from the first findstr
into another findstr
as follows:
findstr /c:"%username%" "ACL.csv" | findstr /c:" %sitenum%," >nul 2>&1
Note:
- the leading
(space) and trailing
,
(comma) are important as this prevents 1 matching 11 (for example)
- An A-Z Index of the Windows CMD command line
- A categorized list of Windows CMD commands
- redirection - Redirection operators.