Parsing CSV vertically and horizontally

T

Tuomas Järvinen

Hi There!

I'm creating a batch file for creating number of new users . It reads config
and data file. The data file is normal CSV file.

first we read config file for data colum names:

@echo off
setlocal
type a.x | find /i "datacolumn" > a2.x
set count=0
set max=0
set inc=1

for /f "eol=# " %%a in ( a2.x ) do
for /f "tokens=1,* delims==" %%g in ("%%a") do (
set %%g=%%h
set %%h=XXX
set /a COUNT+=%inc%
)
)
echo Read %COUNT% columns.


Works fine: I can get datacolun=name and name=XXX from file a2.x.

On second stage we should parse the data from CSV file and put the field to
named variable. (Finally I should have each data field in named variables
so I can - for example - create a new user with net user %username% /add
/domain command).

Here is pseudo-code how I try to do this:

set count = 0 - init counter
loop line in file - loop line by line
set count inc 1 - inc counter
loop pos to Max - loop position to max
loop pos-item in line max - walk each field in line
if item="" item = XXX - if its empthy, put XXX
named=item - save item
endloop
endloop
Do-the-work-here
endloop
End.


And now the code:

set count=0
set pos=0

for /F "eol=#" %%a in ( b.x ) do (
set /a count=%count%+%inc% do (
echo Debug: Line %count%
for /L %%y in (1,1,%MAX) do (
for /F "tokens=%%y delims=;" %%i in ("%%a" ) do (
rem .... do the stuff here, we have now line field %%i from line %%a
rem in %named% variable.
)
)
)


I get error "-10 delims=;" was unexpected at this time." for line
starting with 'for /F "tokens=%%y....' (I suppose...)

If someone can help and/or give some better clue/point/idea..
Reason why I don't use win2k standard import tools (csvde for example), they
does not create and grant permissions home directories, .

Thank you for help.
- Tuomas.



mtjjarvin at yahoo dot com
 
M

Matthias Tacke

Tuomas said:
Hi There!

I'm creating a batch file for creating number of new users . It reads config
and data file. The data file is normal CSV file.
<snip>

Hi Tuomas.
without getting to deep in your code.
And now the code:

set count=0
set pos=0

for /F "eol=#" %%a in ( b.x ) do (
set /a count=%count%+%inc% do (

This do after the set has no for it matches.

HTH
 
T

Tuomas Järvinen

This do after the set has no for it matches.

echo %-(

Uhh.. I miss..
I don't understand....

Can someone help and wrote the code... ( parse a) vertically and b)
horizontally the CSVfile.. ?

With regards, many thankses and so on,

Tuomas.



mtjjarvin at yahoo dot com
 
T

Tuomas Järvinen

Hi There!
Maybye I tried too hard.
CSV File:

Line1, item1, item2, item3
Line2, item1, item2, item3
Line3, item1, item2, item3


1st loop: read line1, line2 and line3. (vertical)
2nd loopI read lineX, item1, item2, item3 (horizontal)

With many thanks..
Tuomas.




mtjjarvin at yahoo dot com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top