Solved Batch file to delete lines in many large CSV file

July 4, 2014 at 02:05:13
Specs: Windows 7
I found here a solution to delete the first lines (here 27) in the csv file:

=======================================
@echo off & setLocal enableDELAYedexpansion

> newfile echo mystring

for /f "skip=27 tokens=* delims= " %%a in (big.csv) do (
>> newfile echo.%%a
)

It works fine but I need to do it for all the files in the folder. I'm new to the batch processing and I do not know how to introduce the loop.

message edited by Gosia


See More: Batch file to delete lines in many large CSV file

Report •

#1
July 4, 2014 at 18:54:58
✔ Best Answer
@echo off >newfile & setLocal enableDELAYedexpansion
for %%f in (*.csv) do (
(for /f "skip=27 tokens=* delims= " %%a in (%%f) do echo.%%a)>newfile
::-- THIS NEXT WILL OVERWRITE THE ORIGINAL FILE!
move /y newfile %%f
)
::======= end script
As noted, use caution, and always back-up to files to another location before run.

Report •

#2
July 5, 2014 at 06:49:32
Many thanks! It works nicely!
I amended the code a bit so it copies the new files to a subfolder:

:: ===== script starts here ===============
@echo off >newfile & setLocal enableDELAYedexpansion
for %%f in (*.csv) do (
(for /f "skip=1 tokens=* delims= " %%a in (%%f) do echo.%%a)>newfile
move /y newfile .\data\noline_%%f.csv
)
::======= end script


Report •
Related Solutions


Ask Question