Computing.Net > Forums > Programming > For loop CSV empty value

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

For loop CSV empty value

Reply to Message Icon

Name: GanjaBlood
Date: April 20, 2009 at 06:28:46 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I am using a CSV file to import users into active directory.

Example CSV:

Surname,First Name,Middle Name,Date of Birth,Student Number,Description

I can extract all the information I need using the following statement;

FOR /F "tokens=1,2,3,4,5,6* delims=," %%A IN (users.csv) DO (

That is until a field is empty, for example no middle name;

Surname,First Name,,Date of Birth,Student Number,Description

The empty value is ignored, not counted as a token which breaks my dsadd user variables.

What can I do, I am stuck!?

Thanks,



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 20, 2009 at 07:32:48 Pacific
Reply:

:: chg ,, to , , to keep blank fields working

@echo off > new.csv & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (old.csv) do (
set str=%%a
set str=!str:,,=, ,!
echo !str! >> new.csv
)


=====================================
If at first you don't succeed, you're about average.

M2


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: For loop CSV empty value

For loop info needed www.computing.net/answers/programming/for-loop-info-needed/20169.html

Batch FOR Loop %ERRORLEVEL% www.computing.net/answers/programming/batch-for-loop-errorlevel/13528.html

using for loops to interate unicode www.computing.net/answers/programming/using-for-loops-to-interate-unicode/12858.html