How do I create a batch file that reads a file and

2019-07-15 14:04发布

I currently have an exported text file (output.txt) from a Clear-Case command that I need to parse. It looks like this:

Comparing the following:
  R1.PROD.V1@\VOB_pvob
  R2.PROD.V1@\VOB_pvob
Differences:
>> M:\ACME_PROD\src\ACME@@
>> M:\ACME_PROD\src\ACME\file 2.txt@@
>> M:\ACME_PROD\src\ACME\file 1.txt@@
>> M:\ACME_PROD\src\ACME\file 3.txt@@

What I would like to do is use the findstr command to filter the strings that are contained between the ">> " and "@@" strings to get an output file that looks like this (with quotes if possible:

"M:\ACME_PROD\src\ACME"
"M:\ACME_PROD\src\ACME\file 2.txt"
"M:\ACME_PROD\src\ACME\file 1.txt"
"M:\ACME_PROD\src\ACME\file 3.txt"

I am new to writing batch files and so I don't exactly know where to start. I have managed to find code that can loop through the lines of a text file and separate code for the findstr command, but I get stuck trying to put it all together!

Best regards,

Andrew

1条回答
混吃等死
2楼-- · 2019-07-15 14:48

Here you go

setlocal enabledelayedexpansion
for /f "skip=1 tokens=* delims=> " %%a in ('"findstr /r [\w^>*] output.txt"') do (
set line=%%a
set line=!line:@=!
echo "!line!" >>new.txt
)

The filtered strings will be outputted into new.txt.

查看更多
登录 后发表回答