• 0

trying to make a batch / cmd file to shift a few columns around in CSV


Question

hi there.

i've got a csv file & i'm just tryign to automate the process of moving a few columns around inside it (it's a product pricelist i get from supplier, and i shift the columns to put it in right order for our database)

so i asked a few people and one guy introduced me to FOR /f & cmd file

so far i have reached this solution:

@echo off
::move column5 to column1
for /f "tokens=1-10 delims=," %%a in (file.csv) do echo %%c,%%h,%%b,%%f,,%%b,%%g,,%%e,dove >> test-output.txt

this seems to work ok!

but now i have encounter this problem. The delimiter is , but the csv file has some fields with , in them. So problem is yes fields are delimited by , but they are Enclosed by " " double quote. So the cmd must only delimit based on , & where there is surrounding quotes!

so I don't know what to do. I guess you could make delims="," but then how do you hand end of line start of line!

anyone have ideas? Maybe there is another programming language that can do this very quick also?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

While I don't exactly know how to do what you are asking, Python is a very good language for doing operations such as this. It has nice string formatting functions.

Link to comment
Share on other sites

  • 0

you can set the write delimiter on ; , or you can use a regex pattern to allow some ,'s

you just have to ask yourself, how do i know which ,'s are delimiters and hwich are not ... then you can make the pattern

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.