You can use PowerShell from cmd.exe console:
powershell -command "& {get-content input.txt|select-object -first 10}" >output.txt
You can create a DOSKEY macro to make it easier to use from the command line:
doskey head=powershell -command "& {get-content $1|select-object -first $2}"
Using:
head input.txt 10 >output.txt
But you cannot use the DOSKEY macro in a script package.
Instead, you can create a head.bat script and put it in the folder that is included in your PATH:
head.bat
@powershell -command "& {get-content %1|select-object -first %2}"
At the command line you should use head input.txt 10 >output.txt
From inside the script package you should use call head input.txt 10 >output.txt
I decided not to have the output file as a parameter if you just want to display the result on the screen instead of writing to the file.
dbenham
source share