How can I print first 5 lines of the file in windows CMD?
There is a problem that I can't use PowerShell (spicific task) and batch scripts. Can you help me with this?
How can I print first 5 lines of the file in windows CMD?
There is a problem that I can't use PowerShell (spicific task) and batch scripts. Can you help me with this?
You should be able to use the more command in some regard.
Maybe "more filename P 5"
Alright, it might be like replying to a very old thread, but still for anyone who would benefit from this.
Use findstr
findstr /n . yourfile.txt | findstr "^[0-5]:"
The breakdown is-
first findstr prints the line number where it finds any character (denoted by a literal dot), second findstr will print lines that start ( using ^ for this ) with any number ranging from 0 through 5. Also include ":" there to avoid findstr matching with recurring digits like 12,13,14... 21,22,23..., etc.
^[0-5]: will match only for lines starting with-
1:
2:
3:
4:
5:
I tested it on a 250 MB file and it worked within a second.
The same can be achieved in linux using sed-
sed -n '1,5p' yourfile.txt