Solved Amending a CSV file via a batch file

April 28, 2014 at 07:53:09
Specs: Windows 7
I need to amend a csv file that could contain 1 line or 100 lines.

The file will be sent thus:


Each line has to be changed to

That is add to first column P change the : to . (semicolon to full stop.
The first number (123456789) could be any length from 1 digit to 9 digits.

Hope someone can help Please (pretty please)

See More: Amending a CSV file via a batch file

Report •

April 28, 2014 at 08:28:26
✔ Best Answer
@echo off & setlocal EnableDelayedExpansion
type nul > "file_new.csv"
for /F "delims=" %%j in ('type "myfile.csv"') do (
  set row=%%j
  set row=!row::=.!
) >> "file_new.csv"

message edited by IVO

Report •

April 28, 2014 at 10:24:29
perfect, many thanks.

Worked first time

Report •

April 28, 2014 at 22:17:49
Hi, whilst that worked. I also need for another csv a similar change, but this time without adding P to the first column of each row, just changing the : to .

I have tried to modify the batch but have not been successful

What have I done wrong?

Report •

Related Solutions

April 29, 2014 at 01:04:04
What you did wrong I don't know since you did not post your change. Anyway to achieve what you need it is sufficient to replace

echo.P,!row! with echo.!row!

or use the following more tense script

@echo off
type nul > "FileOut.csv"
for /F "tokens=1,2 delims=:" %%j in ('type "FileIn.csv"') do (echo.%%j.%%k) >> "FileOut.csv"

Report •

April 29, 2014 at 01:16:45
Many thanks I did remove the "echo.P,!row! with echo.!row!". But the files was created with no entries in it.

I really appreciate your assistance. Got me out of a big jam.

Report •

April 29, 2014 at 02:29:28
Hmm... your issue remains a mistery to me as you apparently did what I suggest. I hope you had the job done. If more support is needed, contact me freely by a private message (click on my avatar then click again on my nickname).

Report •

Ask Question