Computing.Net > Forums > Programming > Remove blank first line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Remove blank first line

Reply to Message Icon

Name: Fut
Date: June 8, 2009 at 14:56:28 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

Hi.
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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: June 8, 2009 at 16:00:06 Pacific
Reply:

@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.

M2


0

Response Number 2
Name: Fut
Date: June 9, 2009 at 15:06:38 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Remove blank first line

Remove text file lines www.computing.net/answers/programming/remove-text-file-lines/14290.html

.bat delete first line of text file www.computing.net/answers/programming/bat-delete-first-line-of-text-file/13773.html

Delete first line of text www.computing.net/answers/programming/delete-first-line-of-text/13312.html