EXTRACT THE 2 FIRST LINES OF A TXT FILE AND COPY TO ANOTHER TXT FILE

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jorgegs
Posts: 22
Joined: 07 Apr 2016 22:56

EXTRACT THE 2 FIRST LINES OF A TXT FILE AND COPY TO ANOTHER TXT FILE

#1 Post by Jorgegs » 11 Apr 2016 00:45

HELO FRIENDS !

I NEED a batch file to extract the 2 first lines of a txt file generated by DU.exe renamed for W7 by me, as Dudir.exe
to bypas de DU command W7. It works perfect.

The information which I get as result in a 1. txt file is:

Files: 125
Directories: 4
Size: 230.456.786 bytes
Size on disk: 230.456.786 bytes

I want to get a new 2.txt file BUT ONLY WITH THE 2 FIRST LINES

Files: 125
Directories: 4

I tryed a lot of posibilities with FOR but I'm not an expert in FOR

Please can some one help me with the correct code

Thanks in advance for the help

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: EXTRACT THE 2 FIRST LINES OF A TXT FILE AND COPY TO ANOTHER TXT FILE

#2 Post by Squashman » 11 Apr 2016 11:36

You could give this a try.

Code: Select all

dudir.exe -n -q |findstr /b /i "Files: Directories:" >file2.txt

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: EXTRACT THE 2 FIRST LINES OF A TXT FILE AND COPY TO ANOTHER TXT FILE

#3 Post by npocmaka_ » 12 Apr 2016 02:20

this will print the first two lines of SOME_FILE.txt:


Code: Select all

break>"%temp%\empty"&&fc "%temp%\empty" "SOME_FILE.txt" /lb  2   /t |more +4|findstr /B /E /V "*****"

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: EXTRACT THE 2 FIRST LINES OF A TXT FILE AND COPY TO ANOTHER TXT FILE

#4 Post by Aacini » 12 Apr 2016 04:45

Code: Select all

@echo off
setlocal

( set /P "line1=" & set /P "line2=" ) < input.txt
(
   echo %line1%
   echo %line2%
) > output.txt

Antonio

Jorgegs
Posts: 22
Joined: 07 Apr 2016 22:56

Re: EXTRACT THE 2 FIRST LINES OF A TXT FILE AND COPY TO ANOTHER TXT FILE

#5 Post by Jorgegs » 12 Apr 2016 09:37

Thank you very much friends

The first solution is perfect
The second close the batch file
The solution 3 give me a message "echo is desactivated"
and in any case what for and why is setlocal necessary ?

Thanks
Jorgegs

Post Reply