Reputation: 99
I have a text file that contains data like this but I want to only get the first two strings of the file. from this:
Caption
SMI USB DISK USB Device
Hitachi HTS547550A9E384
to this:
Caption
SMI USB DISK USB Device
Upvotes: 0
Views: 592
Reputation: 6620
Very simple:
@echo off
3<text.txt (
set /p line1= <&3
set /p line2= <&3
)
Echo %line1%
Echo %line2%
Which is how you get the first to lines of a file. To actually change the file so it only consists of these two lines use:
@echo off
3<text.txt (
set /p line1= <&3
set /p line2= <&3
)
Echo %line1% > text.txt
Echo %line2% >> text.txt
Note: You have to replace text.txt
with the name of your file.
Upvotes: 3
Reputation: 1145
If you have powershell, you can make it by
powershell -command "& {get-content filename -totalcount n}"
Where n
is the number of lines to display.
Upvotes: 0