Created
November 5, 2016 14:20
-
-
Save Jonny007-MKD/ab1ff3c2dd00d47e179d60a50a07fa79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
if [%1] == [] goto usage | |
if [%2] == [] goto usage | |
if [%3] == [] ( | |
set /a offset=0 | |
) else ( | |
set /a offset=%3 | |
) | |
call :print_head %1 %2 %3 | |
goto :eof | |
REM | |
REM print_head | |
REM Prints the first non-blank %1 lines in the file %2. | |
REM | |
:print_head | |
setlocal EnableDelayedExpansion | |
set /a counter=0 | |
for /f ^"usebackq^ eol^=^ | |
^ delims^=^" %%a in (%2) do ( | |
if !offset! GTR 0 ( | |
set /a offset-=1 | |
) else ( | |
if "!counter!"=="%1" goto :eof | |
echo %%a | |
set /a counter+=1 | |
) | |
) | |
goto :eof | |
:usage | |
echo Usage: head.bat COUNT FILENAME [OFFSET] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment