Skip to content

Instantly share code, notes, and snippets.

@Jonny007-MKD
Created November 5, 2016 14:20
Show Gist options
  • Save Jonny007-MKD/ab1ff3c2dd00d47e179d60a50a07fa79 to your computer and use it in GitHub Desktop.
Save Jonny007-MKD/ab1ff3c2dd00d47e179d60a50a07fa79 to your computer and use it in GitHub Desktop.
@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