Squashman wrote:Why are you not using 7 tokens and a comma as the delimiter. Your examples shows that you are only changing those values in the 2nd field. So you should only be assigning the token %%b to an environmental variable and doing string replacement on that environmental variable. Then you will echo out all the tokens and the environmental variable to an output file.
Also your example shows that you are only changing those values when the field is those specific values and does not just contain that value, so you will need to check if that field is equal to that value before you change it.
Sorry for the delayed response as I was bit busy with some other tasks. I really want to thank you as your inputs helped me a lot to reach very near to my goal.
Please have a look at my code, input and output files. Currently the issue I am facing is, I can't convert the SALE to SELL and PURCHASE to BUY in a single script. Doing so I am getting very absurd output. But if I convert them individually then I am getting the perfect output, but in that way the work is becoming double. So could you please suggest me how can I merge both the scripts to get the output in a single run.
Currently I am running one script 1st and taking the output as the input for the other script.
Input File:
Code: Select all
"ABC","SALE","08/13/2015","08/18/2015","-15000.00","GLOBAL SALE","FIXED INCOME - SALE"
"TITAN","PURCHASE","08/12/2015","08/17/2015","55000.00","LOCAL PURCHASE","FIXED INCOME - PURCHASE"
"HUN","SHORT PURCHASE","08/12/2015","08/17/2015","60000.00","GLOBAL SHORT PURCHASE","FIXED INCOME - SHORT PURCHASE"
"WMB","PURCHASE","08/13/2015","08/18/2015","5000.00","GLOBAL PURCHASE","FIXED INCOME - PURCHASE"
"","SHORT SALE","08/13/2015","08/14/2015","-89235.90","LOCAL SHORT SALE","FIXED INCOME - SHORT SALE"
"XYZ","SALE","08/13/2015","08/18/2015","-633.00","GLOBAL SALE","FIXED INCOME - SALE"
Script for SALE to SELL conversion:
Code: Select all
setLocal EnableDelayedExpansion
for /f "tokens=1-7 delims=|" %%a in ('parseCSV.bat "/o:|" ^<INPUT.csv') do (
Set str1=%%b
set str1=!str1:SALE=SELL!
echo "%%~a",!str1!,"%%~c","%%~d","%%~e","%%~f","%%~g">>OUTPUT_SELL.csv
)
Output for SALE to SELL conversion:
Code: Select all
"ABC","SELL","08/13/2015","08/18/2015","-15000.00","GLOBAL SALE","FIXED INCOME - SALE"
"TITAN","PURCHASE","08/12/2015","08/17/2015","55000.00","LOCAL PURCHASE","FIXED INCOME - PURCHASE"
"HUN","SHORT PURCHASE","08/12/2015","08/17/2015","60000.00","GLOBAL SHORT PURCHASE","FIXED INCOME - SHORT PURCHASE"
"WMB","PURCHASE","08/13/2015","08/18/2015","5000.00","GLOBAL PURCHASE","FIXED INCOME - PURCHASE"
"","SHORT SELL","08/13/2015","08/14/2015","-89235.90","LOCAL SHORT SALE","FIXED INCOME - SHORT SALE"
"XYZ","SELL","08/13/2015","08/18/2015","-633.00","GLOBAL SALE","FIXED INCOME - SALE"
Script for PURCHASE to BUY conversion: Here I'm taking output of the SALE to SELL conversion script as input in this script.
Code: Select all
setLocal EnableDelayedExpansion
for /f "tokens=1-7 delims=|" %%a in ('parseCSV.bat "/o:|" ^<OUTPUT_SELL.csv') do (
Set str1=%%b
set str1=!str1:PURCHASE=BUY!
echo "%%~a",!str1!,"%%~c","%%~d","%%~e","%%~f","%%~g">>OUTPUT_BUY.csv
)
Final Output:
Code: Select all
"ABC","SELL","08/13/2015","08/18/2015","-15000.00","GLOBAL SALE","FIXED INCOME - SALE"
"TITAN","BUY","08/12/2015","08/17/2015","55000.00","LOCAL PURCHASE","FIXED INCOME - PURCHASE"
"HUN","SHORT BUY","08/12/2015","08/17/2015","60000.00","GLOBAL SHORT PURCHASE","FIXED INCOME - SHORT PURCHASE"
"WMB","BUY","08/13/2015","08/18/2015","5000.00","GLOBAL PURCHASE","FIXED INCOME - PURCHASE"
"","SHORT SELL","08/13/2015","08/14/2015","-89235.90","LOCAL SHORT SALE","FIXED INCOME - SHORT SALE"
"XYZ","SELL","08/13/2015","08/18/2015","-633.00","GLOBAL SALE","FIXED INCOME - SALE"
Finally I am getting the desired output but in 2-Steps. Could you please help and suggest the required changes needed in my script so that I don't need 2-Steps to achieve the desired output.
Thanks..!!
Shaswat