Solved Manipulate CSV Data using batch File

January 11, 2016 at 11:37:02
Specs: Windows 7
we receive CSV files from vendors, actually in .txt format (tab delimiter). I have to manupulate data on csv file before i upload it to my server.

CSV files comes in format
1 20 QC 100
2 31 QC 500
3 23 ON 700

Below are things i have to do
1) I have to parse data by line and find rows with 3rd column as 'QC'

2) For Row with 3rd column as QC multiply column 4 with 0.1

So output expected is
1 20 QC 10
2 31 QC 50
3 23 ON 700

I appreciate any inputs here.

Thanks
KC


See More: Manipulate CSV Data using batch File

Report •

#1
January 11, 2016 at 18:36:14
✔ Best Answer
This should get it, BUT...

Here comes the but part. Because batch does only whole number math, if column d is 367 it will hit the wall.


::====== script starts here ===============
::
:: KC.bat 2016-01-12 9:24:46.83
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=1-4 " %%a in (myfile) do (
if %%c==QC (
set/a D=%%d/10
echo.%%a %%b %%c !D!
) else (
echo.%%a %%b %%c %%d
)
) >> NEWFILE
::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Report •
Related Solutions


Ask Question