Parsing CSV vertically and horizontally

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Tuomas Järvinen (mtjjarvin_at_yahoo.ReMove-This.com)
Date: 08/16/04


Date: Mon, 16 Aug 2004 19:26:13 GMT


 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



Relevant Pages

  • Re: Is there an easy way to bring my wifi card at boot / init 3?[Scanned]
    ... case) and created a proper wpa_supplicant config file. ... echo $"$alias device $does not seem to be present, ... /sbin/ip link set dev $down ...
    (Fedora)
  • [PATCH]-2.4.23 switches to kbuild
    ... +All random configurations will satisfy the config rules, that is, all ... +values take precedence over lists which take precedence over range. ... +defconfig: symlinks ... echo "# Using defaults found in" $DEFAULTS ...
    (Linux-Kernel)
  • Re: [PATCH] Miniconfig revisited (2/3)
    ... re-parsing the config file 1500 times or so for defconfig. ... +# shrinkconfig copyright 2006 by Rob Landley ... echo "Turns current .config into a miniconfig file." ...
    (Linux-Kernel)
  • Re: [PATCH 4/4] kconfig: streamline_config.pl: let users specify the list of desired modules
    ... The current localmodconfig is designed to be run on your own system, ... and a novice user may just assume an old distribution config file ... @echo ' localyesconfig - Update current config converting local mods to core' ... @echo ' silentoldconfig - Same as oldconfig, but quietly, additionally update deps' ...
    (Linux-Kernel)
  • diet-kconfig: a script to trim unneeded kconfigs
    ... unneeded kernel configs automatically to reduce the compile time. ... I already wrote such a script during the last SUSE hack ... You can specify the config file via option, as default, it reads from ... echo "Cannot find module list file modulelist" ...
    (Linux-Kernel)