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

  • SEARCH
  • Home
  • 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 7971917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:44:08+00:00 2026-06-04T07:44:08+00:00

I have a csv file like this name,sex,age venu,m,16 test,,22 [EDIT] name could have

  • 0

I have a csv file like this

name,sex,age
venu,m,16
test,,22

[EDIT]
name could have comma also

"venu,gopal",m,16

I want to handle if sex is nothing and save it to another file.

I have a script like this

@Echo Off
For /F "usebackq tokens=1-3  delims=," %%a in (test.csv) Do (
   echo %%a, %%b, %%c >> test-new.csv
)

But for the third record, I am getting %%b as 22 which should be space. How to fix this?

[EDIT2]

I have tried as per that link. I am not sure what I am doing wrong. I am getting same issue. Please check it once.

@echo off
setlocal DisableDelayedExpansion

For /F "usebackq tokens=1-3 delims=" %%x in (C:\somefile.csv) Do (

    setlocal EnableDelayedExpansion
    set "var=%%x"   

    set "var=!var:"=""!"
    set "var=!var:^=^^!"
    set "var=!var:&=^&!"
    set "var=!var:|=^|!"
    set "var=!var:<=^<!"
    set "var=!var:>=^>!"
    set "var=!var:,=^,^,!"
    set var=!var:""="!
    set "var=!var:"=""Q!"
    set "var=!var:,,="S"S!"
    set "var=!var:^,^,=,!"
    set "var=!var:""="!"
    set "var=!var:"Q=!"


    For /F "tokens=1-3  delims=," %%a in ("!var:"S"S=","!") Do (
      endlocal
      echo %%~a, %%~b, %%~c
      setlocal EnableDelayedExpansion
      pause
    )

    endlocal

)
  • 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-04T07:44:09+00:00Added an answer on June 4, 2026 at 7:44 am

    This is a bit tricky, as multiple delims will be condensed to a single delim.

    So you need to replace them before to a unique delim sequence.

    @Echo Off
    setlocal DisableDelayedExpansion
    For /F "usebackq tokens=1-3  delims=" %%a in (test.csv) Do (
        set "line=%%a"
        setlocal EnableDelayedExpansion
        set "line="!line:,=","!""
        For /F "tokens=1-3  delims=," %%a in ("!line!") Do (
            echo %%~a, %%~b, %%~c 
        )
    )
    

    This enclose each column into quotes, and with the %%~a the quotes will be removed later

    EDIT: The solution for embedded commas

    In this case it’s only a bit different than the solution for how to split on ‘;’ in CMD shell

    @echo off
    setlocal DisableDelayedExpansion
    
    For /F "usebackq tokens=1-3 delims=" %%x in (test.csv) Do (
        set "var=%%x"
        setlocal EnableDelayedExpansion
        set "var=!var:^=^^!"
        set "var=!var:&=^&!"
        set "var=!var:|=^|!"
        set "var=!var:<=^<!"
        set "var=!var:>=^>!"
        set "var=!var:,=^,^,!"
        rem ** This is the key line, the missing quote is intention
        call set var=%%var:""="%%
        set "var=!var:"="Q!"
        set "var=!var:^,^,="C!"
        set "var=!var:,,=,!"
        set "var=!var:""="!"
    
        set "var="!var:,=","!""
        for /F "tokens=1-3 delims=," %%a in ("!var!") do (      
            endlocal
            set "col1=%%~a"
            set "col2=%%~b"
            set "col3=%%~c"
            setlocal EnableDelayedExpansion
            if defined col1 (
                set "col1=!col1:"C=,!"
                set "col1=!col1:"Q="!"
            )
    
            if defined col2 (
                set "col2=!col2:"C=,!"
                set "col2=!col2:"Q="!"
            )
    
            if defined col3 (
                set "col3=!col3:"C=,!"
                set "col3=!col3:"Q="!"
            )
            echo a=!col1!, b=!col2!, c=!col3!
            endlocal
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file formatted just like this: name,color,tasty,qty apple,red,true,3 orange,orange,false,4 pear,greenish-yellowish,true,1 As
I have some lines in a CSV file like this: 1000001234,Account Name,0,0,3,711.32,0,0,18,629.64,22,340.96,COD,20,000.00,Some string,Some string
I have a CSV file with lines like this: AAA,A-name,num1,num2,num3 BBB,B-name,num1,num2,num3 CCC.DDD,C-name,num1,num2,num3 EEE.FFF.GGGG,E-name,num1,num2,num3 HHH.H-name,num1,num2,num3
I have a file called test.csv, Data in the file is looking like this:
I have a csv file which is something like this: book_store_id book_price name 1
Ok, I have a csv file like this: 14 ; 1234,56 ; 10203 ;
I have a list of dictionaries that looks something like this: toCSV = [{'name':'bob','age':25,'weight':200},{'name':'jim','age':31,'weight':180}]
I have a CSV file, formatted like this: 0001 @ word @ some information
I have a csv file that looks something like this (actual file has many
I have csv file like this: item,#RGB item1,#ffcc00 item1,#ffcc00 item1,#ff00cc item2,#00ffcc item2,#ffcc00 item2,#ffcc00 item2,#ffcc00

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.