China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-22 07:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to read text line by line in batch processing without setting it as a variable? View 3,310 Replies 23
Floor 16 Posted 2006-04-05 15:17 ·  中国 广东 广州 白云区 电信
初级用户
Credits 100
Posts 34
Joined 2006-04-05 05:13
20-year member
UID 53340
Gender Male
Status Offline
Brother on the 3rd floor, I'm sorry I didn't understand it originally, but now I've got it. Yours is executable. But I still don't know how to reference the value of a variable. My purpose is like this: First read a line from a.txt, then search in b.txt. If there is no such content in b.txt, add it; if there is, skip it. I realized that my original expression wasn't accurate. I'm sorry.

In addition, you mentioned that you can use a goto loop. I sort of understand the idea, that is, first read a line, then jump to the corresponding program segment accordingly. But now my problem is that I simply don't know how to read a line from a.txt? Using FOR reads until it's done, what should I do?

Thank you in advance!
Floor 17 Posted 2006-04-05 18:09 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Yeah, many times it's very important to describe the problem clearly. If you don't know how to describe the steps to solve the problem, just make clear what you want to do.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 18 Posted 2006-04-05 20:57 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
It's not that I don't understand, but the owner of the post changes too fast.
Hehe, your requirements have changed a lot.
If you don't want to use type, then try findstr + type:
findstr /v /g:b.txt a.txt >>tmp.txt
type tmp.txt >> b.txt
Not tested, theoretically it works, I think this method is more suitable for you than the previous one.
Floor 19 Posted 2006-04-06 01:09 ·  中国 山东 菏泽 电信
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
Floor 20 Posted 2006-04-06 03:07 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re 3742668:

It is estimated that the variable in the original poster's mind is not the environment variable, but the replacement variable of for, which is easier to understand.

In addition, your code is indeed skillful, and with a little modification, it can be used to extract the specified lines in the text, which is an algorithm with universal significance.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 21 Posted 2006-04-06 16:37 ·  中国 广东 广州 白云区 电信
初级用户
Credits 100
Posts 34
Joined 2006-04-05 05:13
20-year member
UID 53340
Gender Male
Status Offline
RE: 3742668

Big brother, thank you! I tested your method, and it turns out to be feasible! Thanks a million!

In addition, I encountered some problems during the test:

1) If both a.txt and b.txt originally have content, the result is consistent with the expected goal when running for the first time, but it is inconsistent when running again. Later I found that tmp.txt was empty the first time, and had content the second time. So I added a line after your code: del tmp.txt

2) If b.txt was originally completely empty, then after running the batch processing, it is still completely empty and does not achieve the expected goal. Of course, I can add an irrelevant line in advance, and then it can achieve my expected goal. But I think that is not the proper way.

Do you have any better solutions?
Floor 22 Posted 2006-04-06 16:42 ·  中国 广东 广州 白云区 电信
初级用户
Credits 100
Posts 34
Joined 2006-04-05 05:13
20-year member
UID 53340
Gender Male
Status Offline
RE: willsort
Moderator, hello!
You said that with a little modification, you can extract specified lines. Can you make it clear? I'm a newbie and really can't figure out how to achieve this goal?

findstr /v /g:b.txt a.txt >>tmp.txt
type tmp.txt >> b.txt

Please tell me the modified code?

Thanks
Floor 23 Posted 2006-04-06 18:34 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Shiver first.

Actually, the things you want to achieve are all in several replies, but you just haven't combined them.

Regarding your question:
1) This is not a problem.
2) Use set /p tmpvar=<b.txt to obtain it, and then use if defined tmpvar to judge whether it is empty.

Finally, shiver again. What willsort said about slightly transforming is not the part of type+findstr, but the previous for. Hehe, it is suggested that you turn over old posts more and run command /?.
Floor 24 Posted 2006-10-02 17:08 ·  中国 湖北 武汉 电信
新手上路
Credits 4
Posts 2
Joined 2006-09-28 11:38
19-year member
UID 63933
Status Offline
Good post, Moderator 3742668 is really enthusiastic!
Forum Jump: