This is my first batch program, and I searched the Internet, but am still trying to write a solution.
I have the following CSV file:
"RH",2013/06/15 02:14:58 -0400,"X","LQ3SUEEWPWKL6",005, "FH",01 "SH",2013/06/14 00:00:00 -0400,2013/06/14 23:59:59 -0400,"LQ3SUEEWPWKL6","" "CH","TransactionID","InvoiceID", ......
I am trying to write a simple program to do the following:
- If column1 = "RH", then retrieve the value of column2 (2013/06/15 02:14:58 -0400)
- If column1 = "SH", then extract the value of column4 (LQ3SUEEWPWKL6)
and channel output to a file.
This is my code so far, but the if condition is not working for me
@echo off :: Set input file in variable ::Set _InputFile=%1 :: Store input line into different variables FOR /F "tokens=1-18* delims=," %%A IN (%_InputFile%) DO ( Set _var1=%%A Set _var2=%%B Set _var3=%%C Set _var4=%%D Set _var5=%%E Set _var6=%%F Set _var7=%%G Set _var8=%%H Set _var9=%%I Set _var10=%%J Set _var11=%%K Set _var12=%%L Set _var13=%%M Set _var14=%%N Set _var15=%%O Set _var16=%%P Set _var17=%%Q Set _var18=%%R IF "%_var1%"=="RH" echo %var2% )
My CSV file looks great in Excel and Notepad, but when I run the script to display the first variable, it looks like some garbage characters are in front of βRHβ on the first record - I cannot get around it, since I need to extract additional column data if var1 = "RH":
β©ββ"RH" FH 01 SH CH TransactionID,PaymentTrackingID, SF SF SC RF CAD,CR,0 RF USD,CR,0 RC FF
windows cmd for-loop csv batch-file
user2550880
source share