Solved Edit Many CSV Files

August 25, 2015 at 07:26:02
Specs: Windows 7
I have a bunch of csv files that I need to replace any percent signs with commas and also remove the top two rows of the file (the top two rows appear to be blank). Is there an easy way to do this without open each and every file?

See More: Edit Many CSV Files

Report •

August 25, 2015 at 11:44:13
✔ Best Answer
Try the following:

@Echo off
setlocal enabledelayedexpansion
cd "%~dp0"
for /f %%A in ('dir /b "*.csv" 2^>nul') do (
	Echo Processing %%A...
	set counter=0
	for /f "skip=2" %%B in (%%A) do (
		set /a counter=!counter!+1
		Echo     Line !counter!...
		set line=%%B
		set line=!line:%%=,!
		Echo !line!>>processed_%%A
Echo Done.
pause > nul

This handles .csv files by default. To change, you replace the *.csv in

for /f %%A in ('dir /b "*.csv" 2^>nul')
with the file type of your desire.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ

Report •

August 25, 2015 at 11:55:50
I should point out you're adding commas to a Comma Separated Values file. Are you trying, to borrow Excel nomenclature, to add additional columns?

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question