简体   繁体   English

从txt文件提取数据?

[英]extracting data from txt file?

Extract data from a text file, the file consists of the following, say: 从文本文件中提取数据,该文件包含以下内容:

<img src="a.jpg" alt="abc" height="12px" width="12px">
<div class="ab3" id="1122">
<img src="b.jpg" alt="abc" height="12px" width="12px">
<div class=cd5" id="9876">

I want to extract the "id" value from the above shown text file... the output should be: 我想从上面显示的文本文件中提取“ id”值...输出应为:

1122
9876

I tried using findstr, find etc(DOS-COMMANDS), but not able to find the perfect regular expression for the same, 我尝试使用findstr,find etc(DOS-COMMANDS),但无法找到相同的理想正则表达式,

any other way is there, any help? 还有其他方法,有帮助吗?

I agree with @izogfif, you should consider some other tools for this task. 我同意@izogfif,您应该考虑使用其他一些工具来完成此任务。

But, to answer what you asked for, I got this regex: 但是,为了回答您的要求,我得到了这个正则表达式:

id="[0-9]+"

It will give you output like this: 它将为您提供如下输出:

id="1122"
id="9876"

From there you can save those results (or use a pipe, however you do that in DOS), and then this regex: 从那里您可以保存这些结果(或使用管道,但是您可以在DOS中执行此操作),然后保存此正则表达式:

[0-9]*

Will give you this output: 将为您提供以下输出:

1122
9876

Use the following code: 使用以下代码:

( id=")[^"]*"

This will match any Id's value. 这将匹配任何Id的值。

You can replace id with any attribute you are searching for. 您可以将id替换为要搜索的任何属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM