【问题标题】:Extracting text in DOS to separate files在 DOS 中提取文本到单独的文件
【发布时间】:2014-12-09 23:54:54
【问题描述】:

我有兴趣将 txt 文件从 word_A 解析到 word_B 并将输出发送到新文件 (new_file_1.txt)...每次在原始 txt 文件中找到 word_A 和 word_B 时,然后推送输出到 new_file_2.txt +N... 继续

我的目标是在两个 xml 标签之间提取 txt 并将输出存储到单独的文件中......

谢谢...由于我是新手,我应该提到您的回复/帮助越详细越好。

这也可以在dos中完成吗?我没有编译器来运行代码...

【问题讨论】:

  • 在批处理文件中这将是一个艰难的过程。

标签: xml batch-file text extract doc


【解决方案1】:

强硬,笨蛋。只需要回收旧批次。

确实取决于您的数据格式 - 但您尚未提供示例。

Here's one I solved earlier

q23655846.txt中的样本数据

<root>
<cities>
        <cityName>paris</cityName>
        <cityName>london</cityName>
        <cityName>...</cityName> 
        ...         
</cities>
<countries>
        <countryName>india</countryName>
        <countryName>japon</countryName> 
        <countryName>...</countryName>  
        ...         
</countries>
<continents>
        <continentName>asia</continentName>
        <continentName>america</continentName>
        <continentName>South america</continentName>
        <continentName>...</continentName>
        ...     
</continents>
</root>

修改代码以适应“每个在其自己的文件中”的要求:

@ECHO OFF
SETLOCAL
SET "outloc=U:\destdir\file_"
set "tag=continentName"
set "f_xml=q23655846.txt"

set "tag2=/%tag%"
setlocal enabledelayedexpansion enableextensions

set fcnt=0
for /f  "tokens=2-4delims=<>" %%a in (%f_xml%) do (
 IF "%%a"=="%tag%" IF "%%c"=="%tag2%" SET /a fcnt+=1&>>"%outloc%!fcnt!" ECHO(%%b
)
GOTO :eof

outloc的设置留给你-我贴的位置方便我的系统。同上标签和 xml 文件名。

如果您想输出一个块,或者您的绝对源文件名包含空格等分隔符,则需要进行少量更改。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    相关资源
    最近更新 更多