Windows Batch Scripting: Parse CSV file and extract data -


i new windows batch scripting pardon ignorance. have csv file looks this:

columna,columnb,columnc 01/02/2015,abc,111 01/03/2015,def,222 01/03/2015,hhh,333 01/05/2015,xyz,767 

the number of rows in file vary columns remain same. need extract date column a, row 1 , date column a, last row.

in case need extract 01/02/2015 , 01/05/2015. next want store both these dates in separate variable.

how can achieve this? have no idea begin. thing have this:

for /f "tokens=1 delims=," %%s in (intflow.csv) @echo %%s 

this 1 line of code cuts first column , echo's it. don't know next. please advice.

use for /f loop parse csv file line-by-line. use skip=1 skip header row. set first variable if isn't defined. set last variable on every loop iteration. it's bound correct sooner or later, right? :)

@echo off setlocal  set "first=" set "last="  /f "skip=1 usebackq delims=," %%i in ("test.csv") (     if not defined first set "first=%%~i"     set "last=%%~i" )  echo %first% echo %last% 

tokens=1 default behavior. usebackq allows enclose filename in quotes, should work if csv filename includes space or other unsavory character in name.


i see in comment you've decided use powershell instead. here's powershell script that'll let populate variables dates.

$csv = ipcsv test.csv $first = ($csv | select -first 1 | %{ $_.columna }) $last = ($csv | select -last 1 | %{ $_.columna })  $first $last 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -