Remove blank first line

June 8, 2009 at 14:56:28
Specs: Windows Vista
I need to remove the first (or 2) blank lines in around 2000 txt-files.

I've found and tried this:
@echo off
setLocal EnableDelayedExpansion
if exist *.new del *.new
for /f "tokens=*" %%A in ('dir /b *.txt') do (
set NAME=%%~nA
set fileNAME=%%A
for /f "tokens=*" %%L in (!fileNAME!) do (
echo %%L >> !NAME!.new

But it removes ALL empty lines in the txt-files. It's songs, and there is 1-2 empty lines first, then a verse, an empty line, verse 2 and so on - and I need the empty lines between verses, but none at the file-top. Is it possible to delete only the first line ? (And maybe check if it's blank before - gives the possibility to run the files again to remove the blank lines in the files with 2 empty lines).
Thanks, Soren from Denmark.

See More: Remove blank first line

Report •

June 8, 2009 at 16:00:06
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "skip=2 tokens=1* delims=[]" %%a in ('find /v /n "" ^< myfile') do (
if "%%b" neq "" (
echo %%b >> newfile
) else (
echo. >> newfile

If at first you don't succeed, you're about average.


Report •

June 9, 2009 at 15:06:38
Thanks ! Works fine (on 1 file at a time).
Can't figure out how to make it take all *.txt files in a directory, process (delete first line) and save in original (or new) file-name.
Any ideas are much appreciated !

Can't figure out what the "if "%%b" neq "" -line is doing ?

Thanks for your help.

Report •

Related Solutions

Ask Question