Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
i need to cancel the first 4 empty lines of 6000 text files with the same structure.Someone can help me?Maybe with a script that is able to do so and save te result?Is it possible to do it with a batch file?(i qould not be able to do it...)

I think it can be done in batch.
By "the first 4 empty lines" do you mean blank lines like this:
####
one
twothree
four
five
#######
=====================================
If at first you don't succeed, you're about average.M2Go

Hi
When you say cancel I'm asumming you mean delete the blank lines.
Are the 4 blank lines at the begining of each file or scattered throughtout the files.

How big are the files?
=====================================
If at first you don't succeed, you're about average.M2Go

Yes,i mean delete.The blank lines are at the beginning of each text file and each text file is less than 10KB.

Hi,
This simple script will delete all the blanl lines, no matter where they are in the file. Is that what you need?
:: noblank.bat
@echo offfor %%F in (*.txt) do call :sub1 %%F
goto :eof:sub1
set outfile=%~n1.out
type nul > %outfile%
for /f "tokens=*" %%L in (%1) do (
echo %%L>> %outfile%
)
goto :eof
:: DONE
If at first you don't succeed, you're about average.M2

Thanks a lot Mechanix2Go but i need something that deletes only the first 4 blank lines of each text file...

Hi,
We're still not quite clear. Can you send me a couple of the files?
If at first you don't succeed, you're about average.M2

Hi Carl
If the first 4 lines are blank and these are to
be deleted but you want to keep any blank lines
after this, try this on some dummy text files
for safety.
@echo off
for %%a in (*.txt) do (
type %%a | find /n /v "~" > ~Temp1.dat
type nul > ~Temp2.dat
for /f "skip=4 tokens=1,* delims=[]" %%c in (~Temp1.dat) do (
if "%%d"=="" ( echo. >> ~Temp2.dat
) else ( echo %%d >> ~Temp2.dat)
)
del %%a
type ~Temp2.dat > %%a
)
del ~Temp?.dat

Hi alastor27
Something I forgot to mension that the linetype %%a | find /n /v "~" > ~Temp1.dat
If there's a "~" in your files that line will be deleted.
If there is, change the "~" to another charactor that you know will not be in any of your files.

Hi alastor27
Glad it worked ok.
Something I forgot to mension that the line
type %%a | find /n /v "~" > ~Temp1.dat
If there's a "~" in your files that line will be deleted.
If there is, change the "~" to another charactor that you know will not be in any of your files.

Hi dtech10,
Im having no luck with your bat.
Original:
#####################
EUR EuroGBP United Kingdom Pounds
CAD Canada Dollars
AUD Australia Dollars
JPY Japan Yen
INR India Rupees
NZD New Zealand Dollars
CHF Switzerland Francs
ZAR South Africa Rand
AFN Afghanistan Afghanis
ALL Albania Leke
DZD Algeria Dinars
ARS Argentina Pesos
AUD Australia Dollars
BSD Bahamas Dollars
######################result:
######################
CAD Canada DollarsAUD Australia Dollars
JPY Japan Yen
INR India Rupees
NZD New Zealand Dollars
CHF Switzerland Francs
ZAR South Africa Rand
AFN Afghanistan Afghanis
ALL Albania Leke
DZD Algeria Dinars
ARS Argentina Pesos
AUD Australia Dollars
BSD Bahamas Dollars
BHD Bahrain Dinars
BDT Bangladesh Taka
BBD Barbados Dollars
BMD Bermuda Dollars
BRL Brazil Reais
############They're bigger, but that's the interesting part.
If at first you don't succeed, you're about average.M2

Hi Mechanix
Computers who'ed buy such a tempermental devices.
Are you recieving error message's are you not sure how it works.

Hi dtech10,
No errors. Here's the before & after on a smaller file:
### before
EUR EuroGBP United Kingdom Pounds
CAD Canada Dollars
AUD Australia Dollars
JPY Japan Yen
INR India Rupees
NZD New Zealand Dollars
CHF Switzerland Francs
ZAR South Africa Rand
AFN Afghanistan Afghanis
ALL Albania Leke
### end before### after
CAD Canada DollarsAUD Australia Dollars
JPY Japan Yen
INR India Rupees
NZD New Zealand Dollars
CHF Switzerland Francs
ZAR South Africa Rand
AFN Afghanistan Afghanis
ALL Albania Leke
### end afterLooks like it removes the first 4 lines regardless of whether they are blank or non-blank.
If at first you don't succeed, you're about average.M2

Hi Mechanix
This would do the trick.@echo off
setlocal EnableDelayedExpansion
set Count=0
for %%a in (*.txt) do (
type %%a | find /n /v "~" > ~Temp1.dat
type nul > ~Temp2.dat
for /f "tokens=1,* delims=[]" %%c in (~Temp1.dat) do (
if "%%d"=="" (
set /a Count=!Count!+1
if !Count! GTR 4 echo. >> ~Temp2.dat
) else ( echo %%d >> ~Temp2.dat )
)
del %%a
type ~Temp2.dat > %%a
)
del ~Temp?.dat
setlocal

Hi dtech10,
Yup, except the last line needs to be endlocal.
Thanks.
If at first you don't succeed, you're about average.M2

I am trying to remove all the blank lines in a file but am having trouble with the first set since it's replacing all my blank lines with "Echo is off."
So I guess the blank lines are gone but this isn't what I had in mind.

![]() |
![]() |
![]() |

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