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?
Question
azuranz
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:
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