中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-15 12:23
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » How to read a text file in the following format with a script? [Solved, thanks to everyone.]
Printable Version  5,594 / 33
Floor1 gyfhgyfh Posted 2007-01-03 11:51
初级用户 Posts 25 Credits 54
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 ]
Floor2 jmz573515 Posted 2007-01-03 21:02
银牌会员 Posts 464 Credits 1,212
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.

Floor3 ccwan Posted 2007-01-03 21:22
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
```
for /f "tokens=2 delims==" %%i in (test.txt) do (>>my.txt echo %%i)
```
Floor4 gyfhgyfh Posted 2007-01-03 22:23
初级用户 Posts 25 Credits 54
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 ]
Floor5 jmz573515 Posted 2007-01-03 22:54
银牌会员 Posts 464 Credits 1,212
It can be done in the same way as the above code.
Floor6 ccwan Posted 2007-01-03 23:00
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
The code is as follows
Floor7 ccwan Posted 2007-01-03 23:04
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
In fact, removing the dot after echo is sufficient. ^_^
Floor8 gyfhgyfh Posted 2007-01-03 23:10
初级用户 Posts 25 Credits 54
Very good, very good.

Now let's continue to go deeper and connect the extracted content in the following format and output:

(Path) + (FileName)
Floor9 ccwan Posted 2007-01-03 23:13
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Floor10 gyfhgyfh Posted 2007-01-03 23:17
初级用户 Posts 25 Credits 54
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 ]
Floor11 ccwan Posted 2007-01-03 23:28
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Is there only one paragraph?
[XXXXXXXX...]
XXX...=...
FileName=***...
XXX...=...
Path=.../
...
Floor12 gyfhgyfh Posted 2007-01-03 23:31
初级用户 Posts 25 Credits 54
-----------------------------------------------------------------------------------------

[XXXXXXXX...]
XXXXX...=***...
XXXX...=.../
XXX...=...
...



[XXXXXXXX...]
XXX...=...
FileName=***...
XXX...=...
Path=.../
...


[XXXXXXXX...]
...
FileName=***...
...


[XXXXXXXX...]
FileName=***...
...
Path=***.../.../...
...

-------------------------------------------------------------------------------------------
Character positions are not fixed.
Floor13 ccwan Posted 2007-01-03 23:37
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
How to correspond when the number of FileName and Path is unequal? Please make it clear.
Floor14 gyfhgyfh Posted 2007-01-03 23:45
初级用户 Posts 25 Credits 54
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
...
----------------------------------------------------------------
Floor15 namejm Posted 2007-01-03 23:52
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Hehe, this is simple. Just combine every two lines into one line.
1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023