|
gyfhgyfh
初级用户
 
积分 54
发帖 25
注册 2006-9-29
状态 离线
|
『楼 主』:
如何用脚本读取下面格式的文本文件?[已结,多谢各位。]
使用 LLM 解释/回答一下
如何用脚本读取下面格式的文本文件,
并取出
FileName=
Path=
后面的字符串输出到 my.txt
-----------------------------------------------------------------------------------------
FileName=***...
Path=.../
FileName=***...
Path=***.../.../
FileName=***...
Path=***.../.../...
-------------------------------------------------------------------------------------------
Last edited by gyfhgyfh on 2007-1-10 at 07:29 AM ]
How to use a script to read the text file in the following format,
and extract the strings after
FileName=
Path=
and output to my.txt
-----------------------------------------------------------------------------------------
FileName=***...
Path=.../
FileName=***...
Path=***.../.../
FileName=***...
Path=***.../.../...
-------------------------------------------------------------------------------------------
Last edited by gyfhgyfh on 2007-1-10 at 07:29 AM ]
|
|
2007-1-3 11:51 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
用VBS写的,把你要提取的文件命名为a.txt之后把下面的内容另存为ss.vbs,双击运行,注意要和a.txt文件在同一个目录下。
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile("a.txt",1)
do while file.AtEndOfStream <> True
n=file.readline
if left(n,9)="FileName=" then m=m&right(n,len(n)-9)&vbcrlf
if left(n,5)="Path=" then m=m&right(n,len(n)-5)&vbcrlf
loop
file.close
set file=fso.createtextfile("my.txt",true)
file.write m
file.close
msgbox "提取内容成功!请查看my.txt文件。",48+4096,"操作完成"
Written in VBS, name the file you want to extract as a.txt, then save the following content as ss.vbs, and double - click to run it. Note that it should be in the same directory as the a.txt file.
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile("a.txt",1)
do while file.AtEndOfStream <> True
n=file.readline
if left(n,9)="FileName=" then m=m&right(n,len(n)-9)&vbcrlf
if left(n,5)="Path=" then m=m&right(n,len(n)-5)&vbcrlf
loop
file.close
set file=fso.createtextfile("my.txt",true)
file.write m
file.close
msgbox "Extraction successful! Please check the my.txt file.",48+4096,"Operation completed"
|
|
2007-1-3 21:02 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
for /f "tokens=2 delims==" %%i in (test.txt) do (>>my.txt echo %%i)
```
for /f "tokens=2 delims==" %%i in (test.txt) do (>>my.txt echo %%i)
```
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-1-3 21:22 |
|
|
gyfhgyfh
初级用户
 
积分 54
发帖 25
注册 2006-9-29
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
非常好,感谢两位。
来个更复杂的,即字符出现的位置不是固定的:
如何用脚本读取下面格式的文本文件,
并取出
FileName=
Path=
后面的字符串输出到 my.txt
-----------------------------------------------------------------------------------------
XXXXX...=***...
XXXX...=.../
XXX...=...
...
XXX...=...
FileName=***...
XXX...=...
Path=.../
...
...
FileName=***...
...
FileName=***...
...
Path=***.../.../...
...
-------------------------------------------------------------------------------------------
Last edited by gyfhgyfh on 2007-1-3 at 10:49 PM ]
Very good, thank you two.
Here's a more complex one where the positions of characters aren't fixed:
How to use a script to read the text file in the following format,
and extract the strings after
FileName=
Path=
and output them to my.txt
-----------------------------------------------------------------------------------------
XXXXX...=***...
XXXX...=.../
XXX...=...
...
XXX...=...
FileName=***...
XXX...=...
Path=.../
...
...
FileName=***...
...
FileName=***...
...
Path=***.../.../...
...
-------------------------------------------------------------------------------------------
Last edited by gyfhgyfh on 2007-1-3 at 10:49 PM ]
|
|
2007-1-3 22:23 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
用上面的代码一样可以完成。
It can be done in the same way as the above code.
|
|
2007-1-3 22:54 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
代码如下
for /f "tokens=1,2 delims==" %%i in (test.txt) do (
if "%%i"=="FileName" (>>my.txt echo. %%j)
if "%%i"=="Path" (>>my.txt echo. %%j)
)
The code is as follows
for /f "tokens=1,2 delims==" %%i in (test.txt) do (
if "%%i"=="FileName" (>>my.txt echo. %%j)
if "%%i"=="Path" (>>my.txt echo. %%j)
)
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-1-3 23:00 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
其实去掉echo后的.就够用了。^_^
In fact, removing the dot after echo is sufficient. ^_^
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-1-3 23:04 |
|
|
gyfhgyfh
初级用户
 
积分 54
发帖 25
注册 2006-9-29
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
非常好,非常好。
现在让我们一起来继续深入,把提取到的内容按以下格式进行连接并输出:
(Path) + (FileName)
Very good, very good.
Now let's continue to go deeper and connect the extracted content in the following format and output:
(Path) + (FileName)
|
|
2007-1-3 23:10 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
|
2007-1-3 23:13 |
|
|
gyfhgyfh
初级用户
 
积分 54
发帖 25
注册 2006-9-29
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
输出
XXX...=...
FileName=abc
XXX...=...
Path=c:\
...
里面的 (Path=.../ ) + (FileName=***...)
即:c:\abc
Last edited by gyfhgyfh on 2007-1-3 at 11:18 PM ]
Output
XXX...=...
FileName=abc
XXX...=...
Path=c:\
...
The (Path=.../ ) + (FileName=***...)
That is: c:\abc
Last edited by gyfhgyfh on 2007-1-3 at 11:18 PM ]
|
|
2007-1-3 23:17 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
只有一段吗?
[XXXXXXXX...]
XXX...=...
FileName=***...
XXX...=...
Path=.../
...
Is there only one paragraph?
XXX...=...
FileName=***...
XXX...=...
Path=.../
...
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-1-3 23:28 |
|
|
gyfhgyfh
初级用户
 
积分 54
发帖 25
注册 2006-9-29
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
-----------------------------------------------------------------------------------------
[XXXXXXXX...]
XXXXX...=***...
XXXX...=.../
XXX...=...
...
[XXXXXXXX...]
XXX...=...
FileName=***...
XXX...=...
Path=.../
...
[XXXXXXXX...]
...
FileName=***...
...
[XXXXXXXX...]
FileName=***...
...
Path=***.../.../...
...
-------------------------------------------------------------------------------------------
字符位置不固定。
-----------------------------------------------------------------------------------------
XXXXX...=***...
XXXX...=.../
XXX...=...
...
XXX...=...
FileName=***...
XXX...=...
Path=.../
...
...
FileName=***...
...
FileName=***...
...
Path=***.../.../...
...
-------------------------------------------------------------------------------------------
Character positions are not fixed.
|
|
2007-1-3 23:31 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
FileName和Path数量不等要如何对应?请讲清楚。
How to correspond when the number of FileName and Path is unequal? Please make it clear.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-1-3 23:37 |
|
|
gyfhgyfh
初级用户
 
积分 54
发帖 25
注册 2006-9-29
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
先简单点吧,提取后的 my.txt 里面的内容格式已经是:
----------------------------------------------------------------
FileName=...
Path=...
FileName=...
Path=...
FileName=...
Path=...
...
----------------------------------------------------------------
如何将 my.txt 输出 Path=...FileName=... 即
----------------------------------------------------------------
c:\abc
...
----------------------------------------------------------------
Let's see. The task is to take the content from my.txt which has lines like FileName=... and Path=... and output Path=...FileName=...
So the steps would be to read each line, split the line to get the Path and FileName parts, then combine them into the desired format.
But since the input is in Chinese and we need to translate the request, the translated text for the process would be:
First, simply put, the content in the extracted my.txt is already in the format:
----------------------------------------------------------------
FileName=...
Path=...
FileName=...
Path=...
FileName=...
Path=...
...
----------------------------------------------------------------
How to output Path=...FileName=... from my.txt, that is
----------------------------------------------------------------
c:\abc
...
----------------------------------------------------------------
Wait, no. Wait the user is asking for the translation of the description. But actually, the task is to process the file. But according to the requirements, just translate the given text.
The original text provided by the user is:
先简单点吧,提取后的 my.txt 里面的内容格式已经是:
----------------------------------------------------------------
FileName=...
Path=...
FileName=...
Path=...
FileName=...
Path=...
...
----------------------------------------------------------------
如何将 my.txt 输出 Path=...FileName=... 即
----------------------------------------------------------------
c:\abc
...
----------------------------------------------------------------
So translating that:
Let's make it simple. The content in the extracted my.txt is already in the format:
----------------------------------------------------------------
FileName=...
Path=...
FileName=...
Path=...
FileName=...
Path=...
...
----------------------------------------------------------------
How to output Path=...FileName=... from my.txt, that is
----------------------------------------------------------------
c:\abc
...
----------------------------------------------------------------
|
|
2007-1-3 23:45 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
呵呵,这个简单,每两行合并为一行就是了。
Hehe, this is simple. Just combine every two lines into one line.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-3 23:52 |
|