#1 17 Oct 2008 18:37

stabbert
Member
Registered: 03 Sep 2008
Posts: 1

Head and Tail for DOS

Anyone have an idea how to implement a Head or Tail function in pure DOS.  Similar to what other scripting languages have?

Offline

#2 18 Oct 2008 02:34

joiners
Member
Registered: 17 Oct 2008
Posts: 7

Re: Head and Tail for DOS

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/

Offline

#3 18 Oct 2008 17:45

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 735
Website

Re: Head and Tail for DOS

In pure DOS? I doubt it, MS DOS is getting very old now

If you meant the Windows CMD shell then something like this:

::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%

If you have the resource kit there is a TAIL.exe included

Offline

Board footer

Powered by FluxBB