Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:56:02+00:00 2026-06-05T06:56:02+00:00

This is extension to another question ( Loop through CSV file with batch –

  • 0

This is extension to another question (Loop through CSV file with batch – Space issue)

I have csv file content like this

name,sex,age,description,date
venu,m,16,test mesg,2012-05-01
test,f,22,"He is good guy
and
brilliant",2012-05-01

I am looping this file using this command.

For /F "usebackq tokens=1-3 delims=" %%x in (test.csv) Do (

But since there is line break in second row, I am getting 3 records even though there are two records in the file.

How to fix this? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:56:03+00:00Added an answer on June 5, 2026 at 6:56 am

    The main problem seems to be to count the quotes in a line.
    If the count of quotes is odd then you need to append the next line and count again the quotes.

    Counting of characters in a string is a bit tricky, if you won’t iterate through all charachters.
    I used here the delayed reduction technic, each quote will be effectivly replaced by a +1 and all other characters are removed.
    To begin and terminate the line in a proper way there is always one extra +1 at the beginning, which will be compensated by a -1 in front.

    The main trick is to replace the complete text from one quote to the next with exactly one +1 by replacing each quote with !!#:#=.
    This works as !#:#=...<some text>...! will always be expanded to +1, as the content of the variable # is +1 and so the search pattern # can’t be found.
    The other replacements are only necessary to avoid problems with exclamation marks and carets int the text.

    :::::::::::::::::::::::::::::::::::::::::::
    :CountQuotes <stringVar> <result>
    setlocal EnableDelayedExpansion
    set "line=!%~1!"
    set "#=+1"
    
    rem DelayedExpansion: double all quotes
    set "line=!line:"=""!"
    
    rem DelayedExpansion: remove all carets ^
    set "line=!line:^=!"
    
    rem PercentExpansion: Remove all !
    set "line=%line:!=%"
    
    rem PercentExpansion: Replace double quotes to !!#:#=
    set "line=-1^!#:#=%line:""=^!^!#:#=%"
    
    for /F "delims=" %%X in ("!line!") do (
        set /a count=%%X!
    )
    
    (
        endlocal
        set %~2=%count%
        exit /b
    )
    

    And the logic for appending lines and inserting linefeeds

    @echo off
    setlocal DisableDelayedExpansion
    set "lastLine="
    set LF=^
    
    
    rem Two empty lines
    for /F "delims=" %%A in (test.csv) do (
        set "line=%%A"
        setlocal EnableDelayedExpansion
        set "line=!line:\=\x!"
        if defined lastLine (
            set "line=!lastLine!\n!line!"
        )
    
        call :CountQuotes line quoteCnt
        set /a rest=quoteCnt %% 2
        if !rest! == 0 (
            for %%L in ("!LF!") DO set "line=!line:\n=%%~L!"
            set "line=!line:\\=\!"
            echo Complete Row: !Line!
            echo(
            set "lastLine="
        ) ELSE (
            set "lastLine=!line!"
        )
    
        for /F "delims=" %%X in (""!lastLine!"") DO (
            endlocal
            set "lastLine=%%~X"
        )
    )
    exit /b
    
    :::::::::::::::::::::::::::::::::::::::::::
    :CountQuotes <stringVar> <result>
    setlocal EnableDelayedExpansion
    set "line=!%~1!"
    set "#=+1"
    
    rem DelayedExpansion: double all quotes
    set "line=!line:"=""!"
    
    rem DelayedExpansion: remove all carets ^
    set "line=!line:^=!"
    
    rem PercentExpansion: Remove all !
    set "line=%line:!=%"
    
    rem PercentExpansion: Replace double quotes to !!#:#=
    set "line=-1^!#:#=%line:""=^!^!#:#=%"
    
    for /F "delims=" %%X in ("!line!") do (
        set /a count=%%X!
    )
    
    (
        endlocal
        set %~2=%count%
        exit /b
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an expression like this Expression<Func<IInterface, object>> How do i loop/traverse through all
This is related to another question I asked last week, but the current issue
I use this method (found on another question) to turn my .ui file into
This is an extension to a previous question which was answered. But have a
This question is kind of an extension of Another question , so I'll be
This question is kind of an extension of Another question , so I'll be
This question is an extension from another question of mine @ Need some advice
The CollectionViewSource.GetDefaultView() method is not in Silverlight 3. In WPF I have this extension
This is an extension to the question here . Now I quote CommonsWare There
This question is an extension of this question . It is good that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.