William Hymen said:
I'm very impressed with the script. But since
shell scripting can become unreadable, *please*
add some comments-
::
:: Thanks in advance
::
I find it quite readable, but it requires detailed knowledge of find
and for
The very much enhanced "for" makes this quite compact batch possible.
Read the help "for /?" several times and play around with the options
for some time to get used to them.
Reading here in mpwca and in alt.msdos.batch.nt will show that "for" is
among the most often used and helpful commands.
::StripLastLine.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
:: check if file exists
if not exist %1 goto :eof
:: Use find /C to count all lines and store in variable %lines%
:: option /V reverses the reslt of a nul search and even gets
:: lines with only crlf, uses redirection to avoid file name output.
for /f %%A in ('find /V /C "" ^<%1') do set lines=%%A
:: similar to previous, find option /N precedes every line with the
:: number in square brackets. For reads the number to %%A the
:: line contents to %%B.
for /f "tokens=1,* delims=[]" %%A in ('find /V /N "" ^<%1') do (
:: Output line only if not last one.
:: Use a char different from space after echo to avoid the secho staus
:: being reporting in case %%B is empty.
:: You may do other number comparisons to get different ranges
if %%A LSS %lines% echo/%%B
)
::StripLastLine.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
HTH