2

我正在使用 ClearCase,我想使用批处理脚本来运行通过 cleartool 命令生成的文本文件,并且只提取包含@@字符串的行,从该行的开头提取直到@@字符串并在前后加上引号.

一个示例文本文件是:

"Created automatically as a result of 'Work On' action in ClearQuest"
owner: <owner>
group: <group>
stream: <stream>
title: <title>
change set versions:
  M:\LEVEL1\PROJECT\src\ROOT@@\main\LEVEL1\6
  M:\LEVEL1\PROJECT\src\ROOT\file 7.txt@@\main\LEVEL1\1
  M:\LEVEL1\PROJECT\src\ROOT\folder 2@@\main\LEVEL1\2
  M:\LEVEL1\PROJECT\src\ROOT\folder 2\file 6.txt@@\main\LEVEL1\1
  M:\LEVEL1\PROJECT\src\ROOT\folder 2\file 8.txt@@\main\LEVEL1\1
  M:\LEVEL1\PROJECT\src\ROOT\folder 2@@\main\LEVEL1\1
  M:\LEVEL1\PROJECT\src\ROOT\file 4.txt@@\main\LEVEL1\2
  M:\LEVEL1\PROJECT\src\ROOT@@\main\LEVEL1\5
  M:\LEVEL1\PROJECT\src\ROOT\file 2.txt@@\main\LEVEL1\4
  M:\LEVEL1\PROJECT\src\ROOT\file 1.txt@@\main\LEVEL1\4
  M:\LEVEL1\PROJECT\src\ROOT@@\main\LEVEL1\3
  M:\LEVEL1\PROJECT\src\ROOT@@\main\LEVEL1\3\file 3.txt\main\LEVEL1\1
clearquest record id: <id>
clearquest record State: <state>

我希望输出是:

"M:\LEVEL1\PROJECT\src\ROOT"
"M:\LEVEL1\PROJECT\src\ROOT\file 7.txt"
"M:\LEVEL1\PROJECT\src\ROOT\folder 2"
"M:\LEVEL1\PROJECT\src\ROOT\folder 2\file 6.txt"
"M:\LEVEL1\PROJECT\src\ROOT\folder 2\file 8.txt"
"M:\LEVEL1\PROJECT\src\ROOT\folder 2"
"M:\LEVEL1\PROJECT\src\ROOT\file 4.txt"
"M:\LEVEL1\PROJECT\src\ROOT"
"M:\LEVEL1\PROJECT\src\ROOT\file 2.txt"
"M:\LEVEL1\PROJECT\src\ROOT\file 1.txt"
"M:\LEVEL1\PROJECT\src\ROOT"
"M:\LEVEL1\PROJECT\src\ROOT"

这可能吗?

最好的祝福,

安德鲁

4

1 回答 1

3

干得好

for /f "tokens=*" %%a in ('findstr "@@" log.txt') do (
for /f "tokens=1 delims=@" %%b in ("%%a") do (
echo "%%b" >>new.txt
)
)

提取的字符串将在 中new.txt,只需记住更改log.txt为您的真实文本文件 :)

于 2013-01-25T10:32:43.163 回答