Page 1 of 1

Unable to get no.of lines in a txt file- batch file

Posted: 30 Aug 2014 11:04
by sivasriram
hello guys

given below is my dos command

echo on
cd filelocation
echo umiya >umiya.xls
findstr /R /N "^" file.txt | find /C ":" >>umiya.xls



the execution is correct but the output is something like
umiya
10


i just need it in side by side like

umiya-10

Re: Unable to get no.of lines in a txt file- batch file

Posted: 30 Aug 2014 15:46
by aGerman
A FOR /F loop enables you to output both the text and your line number.

Code: Select all

for /f %%i in ('type "file.txt"^|find /c /v ""') do >"umiya.xls" echo umiya - %%i

Note that you don't create an Excel file even if you use the xls extension.

Regards
aGerman

Re: Unable to get no.of lines in a txt file- batch file

Posted: 30 Aug 2014 23:53
by Yury

Code: Select all

(
set /p="umiya - "<nul
findstr /rn "^" "file.txt"| find /c ":"
)>"umiya.xls"


or

Code: Select all

(
set /p="umiya - "<nul
type "file.txt"| find /c /v ""
)>"umiya.xls"


or

Code: Select all

(
set /p="umiya - "<nul
more<"file.txt"| find /c /v ""
)>"umiya.xls"


.

Re: Unable to get no.of lines in a txt file- batch file

Posted: 31 Aug 2014 11:38
by sivasriram
Yury: thanks it worked :)

Re: Unable to get no.of lines in a txt file- batch file

Posted: 25 Sep 2014 15:33
by sivasriram
hello,

here is my code

cd desktop
e:


cd E:\CTS\Data\Mumbai\CORE\MEHSANA\OutBox\Extracts\IW

(
set /p="Meshana - "<nul
findstr /rn "^" "*25092014*.txt"| find /c ":"
)>"E:\counts\extract-count.xls"

cd ../../../../

cd E:\CTS\Data\Mumbai\CORE\Varachha Bank\OutBox\Extracts\IW


(
set /p="Varacha - "<nul
findstr /rn "^" "*25092014*.txt"| find /c ":"
)>>"E:\counts\extract-count.xls"
cd ../../../../

cd E:\CTS\Data\Mumbai\CORE\SURAT DIST CO-OP BANK\OutBox\Extracts\IW

(
set /p="surat-dist - "<nul
findstr /rn "^" "*250914*.txt"| find /c ":"
)>>>"E:\counts\extract-count.xls"

cd ../../../../

cd E:\CTS\Data\Mumbai\CORE\UMIYA\OutBox\Extracts\IW




(
set /p="umiya - "<nul
findstr /rn "^" "*25092014*.txt"| find /c ":"
)>>>>"E:\counts\extract-count.xls"

cd ../../../../



THE CODE MENTIONED ABOVE IS WRITING VALUES FOR FIRST 2 FILES CORRECTLY BUT FOR 3RD AND 4TH IT WAS NOT ENTERING ANY RECORDS AND ERROR APPEARING LIKE THIS IN DOS

> was unexpected at this time.



SOME ONE PLEASE HELP TO SOLVE THIS

Re: Unable to get no.of lines in a txt file- batch file

Posted: 25 Sep 2014 15:43
by sivasriram
i NEED OUTPUT LIKE


MESHANA-5269
VARACHA-2452
SURAT-5626
UMIYA-45

BUT THE MENTIONED CODE IS WRITING ONLY FIRST TWO RECORDS AND NOT FETCHNING RECORDS FROM 3RD ONE.

Re: Unable to get no.of lines in a txt file- batch file

Posted: 25 Sep 2014 17:48
by Compo
sivasriram wrote:THE CODE MENTIONED ABOVE IS WRITING VALUES FOR FIRST 2 FILES CORRECTLY BUT FOR 3RD AND 4TH IT WAS NOT ENTERING ANY RECORDS AND ERROR APPEARING LIKE THIS IN DOS

> was unexpected at this time.



SOME ONE PLEASE HELP TO SOLVE THIS

Change >>> to >>
and
Change >>>> to >>

Re: Unable to get no.of lines in a txt file- batch file

Posted: 25 Sep 2014 20:12
by Squashman
sivasriram wrote:hello,

here is my code


How about using code tags when you post code.