batch script to multiply lines

January 8, 2012 at 19:35:55
Specs: Windows XP
Hi guys, i currently have a batch script that counts the number of lines in a file and a batch script that reads the file name and outputs the file name. Can anyone provide me with the solution on how to multiply the number of lines in X text file with X file name.
Here is my script.
setlocal enabledelayedexpansion

for /f "tokens=*" %%t in ('dir/b sg*') do (

if !lines! gtr 0 echo !lines!set lines=

for /f "tokens=* skip=1" %%a in (%%t) do (
set /a N+=1
set /a lines+=1
)

if !lines! gtr 0 echo !lines!>>lineX.txt&&set lines=
set filein=%%t
set fileout=!filein:~2,2! !filein:~4,2! !filein:~6,3!
echo !fileout!>>lines.txt
)

echo total is !N!>>lineX.txt
Thanks in advance,
Wei


See More: batch script to multiply lines

Report •


#1
January 9, 2012 at 00:18:43
I don't believe this line if !lines! gtr 0 echo !lines!set lines=

how to multiply the number of lines in X text file with X file name.

What do you mean? Add the filename to the text? If so where would you like it added, beginning or end? Multiply the number of lines using Set /a? Add new text lines?


Please come back & tell us if your problem is resolved.


Report •

#2
January 9, 2012 at 03:33:15
Hi Wahine,
for example a text file name : me he you. Inside the text file has 90 lines. is it possible to output "me he you" 90 times? "me he you" and '90' are variables.
Thanks in advance
Wei

Report •

#3
January 9, 2012 at 13:08:27
Sorry, I still haven't grasped what you want to do.

Seems to me you have a text file named Me He You which contains 90 lines and you want to output the file name 90 times? Then you want to move onto the next file which might contain 50 lines and output the filename 50 times?

Output to where, file or screen or printer?


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
January 9, 2012 at 20:33:51
Hi Wahine,
seems like you got what i meant and the outputs are to be put into 1 single text file.
Thanks in advance
Wei

Report •

#5
January 10, 2012 at 17:16:16
I hope this is what you want...

@echo off>output.txt
cls
setlocal

for /f "tokens=*" %%1 in ('dir /b *.txt') do (

for /f %%A in ('find /c /v "" ^< "%%1"') do (

    for /l %%B in (1,1,%%A) do (

    echo %%1>>output.txt
    )
  )
)

type output.txt


Please come back & tell us if your problem is resolved.


Report •

#6
January 10, 2012 at 19:22:09
Hi Wahine,
it does work but how can i intergrate it into my script as shown above? As in for /f "tokens=* skip=1" and set filein=%%t
set fileout=!filein:~2,2! !filein:~4,2! !filein:~6,3!
where these are the conditions i need for the script to out put the information that i need.
Thanks
Wei

Report •


Ask Question