stabbert
Anyone have an idea how to implement a Head or Tail function in pure DOS. Similar to what other scripting languages have?
----------------------------
#2 18 Oct 2008 02:34
joiners
I use gnu utils on windows...works outstanding. every unix command you could ever want...available to all your windows scripts
Here is the link
http://gnuwin32.sourceforge.net/
----------------------------
#3 18 Oct 2008 17:45
Simon Sheppard
In pure DOS? I doubt it, MS DOS is getting very old now
If you meant the Windows CMD shell then something like this:
Code: Select all
::Tail.cmd:::::::
@Echo OFF
SETLOCAL
:: Print the last n lines of a file to STDOUT
::
:: tail [File] [n]
::
:: n = Number of lines to print, default=10
Set tmpFile=%temp%\~tail.txt
Set _lines_wanted=%2
If [%_lines_wanted%]==[] SET /A _lines_wanted=10
FindStr /r .* %1 >%tmpFile%
For /F "tokens=1 delims=:" %%G in ('findstr /nr ".*" %tmpFile%') Do (Set _num_lines=%%G)
Set /A skip=_num_lines-_lines_wanted
If /I %skip% LEQ 0 Set skip=0
MORE /E +%skip% %tmpFile%
Del %tmpFile%