Cannot echo in the same line in Batch script -
i have txt files contain several lines , need create log out of them store in log following information:
file name
last modified
count of lines containing word "valid"
i've put .bat file splits output in 2 lines.
type nul > filesreceived.txt & %f in (*.log) ( find /c "valid" %f & echo(%~tf)>> logsreceived.txt )
with type nul clear contents of filesreceived.txt file. loop through files of type log.
count lines contain word valid find /c , echo last modified time stamp.
however output looks like:
---------- transaction_20160505_1005a.log: 6492
10/06/2016 04:37 p.m.
i don't know what's generating dashes. i'd have 1 line per log file follows:
transaction_20012b.log: 6492 10/06/2016 04:37 p.m.
hope guys can me.
thanks,
bruce
find
prints dashes if processes file. doesn't, when processing stdin (type file.ext /c |find "string"
prints count only).
there trick write without linefeed: <nul set /p"=hello"
if can live order, it's quite easy assemble it::
@echo off %%f in (*.bat) ( <nul set /p "=%%f %%~tf " type %%f|find /c "echo" )
if want keep order it's little bit more complicated: can't force find
write without linefeed, have use trick (another for
):
@echo off (for %%f in (*.txt) ( <nul set /p "=%%f: " /f %%i in ('type %%f^|find /c "valid"') (<nul set /p "=%%i ") echo %%~tf ))>logsreceived.txt
Comments
Post a Comment