0

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
user352156
  • 99
  • 1
  • 4
  • 14
  • I have not tried anything since i have no knowledge about batch scripting @zb226 – user352156 Feb 25 '15 at 09:13
  • See [this answer](http://stackoverflow.com/a/130298/1529709) for a quasi-implementation in batch of the *nix `head` utility. – zb226 Feb 25 '15 at 09:51

2 Answers2

3

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.

Monacraft
  • 6,510
  • 2
  • 17
  • 29
0

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.

Szymon Roziewski
  • 956
  • 2
  • 20
  • 36