我如何创建一个批处理文件,读取文件,写一个子到另一个文件? [英] How do I create a batch file that reads a file and writes a substring into another file?

查看:87
本文介绍了我如何创建一个批处理文件,读取文件,写一个子到另一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有来自一个明确的案例命令,我需要解析导出的文本文件( output.txt的)。它看起来是这样的:

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@@

我想要做的是使用findstr命令来筛选包含的字符串>> @@ 字符串得到看起来像这样(带引号的输出文件如果可能的话:

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"

我是新来编写批处理文件,所以我不知道到底从哪里开始。我设法找到code,它可以通过一个文本文件,以及单独code为findstr命令的行循环,但我会被卡住试图把它放在一起!

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!

最好的问候,

安德鲁

推荐答案

在这里你去

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
)

过滤后的字符串将被输出到 new.txt

这篇关于我如何创建一个批处理文件,读取文件,写一个子到另一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆