读取日志文件中的多行,并在CSV文件中设置为1行

时间:2014-05-28 16:27:28

标签: windows svn batch-file logging batch-processing

SVN日志文件中的每个修订版都有多行。有时每个ID只有一个修订版,有时可能还有更多(我见过30个)。 每个修订都由分隔符“--------------------------”设置 我们希望将输出重新排序为CSV,每个版本包含1行。 请参阅附加的输入日志和输出日志的链接 以下是输出和输出的链接输入:https://www.dropbox.com/s/vagfdr4foowsegf/output.csv https://www.dropbox.com/s/59l7njeehsrg5p3/svn.log output.csv有5行。每个版本或QUES ID一个

有没有办法用FOR循环来做?

[ FOR /F "delims=~" %%a in (svn.log)  echo %%a  
  set col3 = %%a 
  echo col3 col2 col1 ]  

1 个答案:

答案 0 :(得分:0)

这也处理分隔符行,它似乎从您的示例文件中执行您需要的操作。

这使用名为repl.bat的助手批处理文件(由dbenham提供) - 从以下网址下载:https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

repl.bat放在与批处理文件相同的文件夹中或放在路径上的文件夹中。

@echo off
type "svn.log"|findstr /r /v /c:"^----------"|repl "," " "|repl "^ *([AMD] .*)\r\n" " $1" xm |repl "(^Changed paths:)\r\n" "$1" xm |repl "^[ /t]*$" "" xm |repl "\r\n\r\n" "\r\n" xm |repl "(.*)\r\n(.*)\r\n(.*)\r\n(.*)\r\n" "$4,$3,$1,$2\r\n" xm  > "output.csv"

扩展版也使用VBS:

@echo off
set "fileout=%temp%\svntemp.tmp"
type "svn.log"|findstr /r /v /c:"^----------"|repl "," ";"|repl "^ *([AMD] .*)\r\n" " $1" xm |repl "(^Changed paths:)\r\n" "$1" xm |repl "\r\n" "," xm |repl ",,," "," |repl ",," "," |repl ",," "," |repl "," "\r\n" x >"%fileout%" 

(
 echo Const ForReading = 1, ForWriting = 2
 echo infile = "%fileout%"
 echo Set fso = CreateObject("Scripting.FileSystemObject"^)
 echo Set f1 = fso.OpenTextFile(infile, ForReading^)
 echo Do While not f1.AtEndOfStream
 echo f = f1.readline 
 echo Wscript.echo f  
 echo    if lcase(left(f,14^)^) = "changed paths:" then flag = 1 : line = "" else flag = 0 
 echo       do while flag = 1
 echo          f = f1.readline
 echo             if not lcase(left(f,9^)^) = "ques id: " then line=line + f + "; " else Wscript.echo line : Wscript.echo f : exit do 
 echo       loop
 echo loop
 echo f1.close
)>"%fileout%.vbs"

cscript /nologo "%fileout%.vbs" >"%fileout%.2"

type "%fileout%.2"|repl "(.*)\r\n(.*)\r\n(.*)\r\n(.*)\r\n" "$4,$3,$1,$2\r\n" xm  > "output.csv"
del "%fileout%" "%fileout%.2" "%fileout%.vbs"