Windows – How to display the first 50 lines of a command output in Windows? (the equivalent of Unix command “head”)

command-line-interfacewindowswindows-command-prompt

I need to display the first 50 lines of the output of a command (any command). In other words, I essentially want an equivalent of the Unix "head" command.

but I dont have permission to create file using the command :

C:> netstat -an > temp.txt && for /l %l in (1,1,10) do @for /f "tokens=1,2* delims=:" %a in ('findstr /n /r "^" temp.txt ^| findstr /r "^%l:"') do @echo %b

Since the command executes on a remote server it does not allow creation of files, please help me change this command to pipe with another command.

I am working on a getting a list of only 50 files that have a specific file name pattern e.g. taha_12345_T_T_00987.txt from a specific folder.

Best Answer

Do you have access to PowerShell? It is usually available starting with XP/Server 2003.

C:\powershell
PS C:\netstat -an | select -first 50