I was looking for a way to do a head in Windows and didn’t want to use any third-party software and of course, it had to be on the commandline. So like head I needed it to show X number of lines from the beginning. I don’t know VBScript, so I am sure there is a better/cleaner way to write this but here is what I came up with. If anyone knows an easier way please pass it on.
FileName = WScript.Arguments.Item(0)
NumLines = WScript.Arguments.Item(1)
Else
Wscript.Echo "Usage: cscript.exe head.vbs filename NumberOfLines"
Wscript.Quit
End If
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileName, ForReading)
Dim i
For i = 1 To NumLines
strNextLine = objFile.ReadLine
strLine = strNextLine
Wscript.Echo strLine
Next
objFile.Close
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
line 11
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8