|
alfredhou
初级用户
 
积分 100
发帖 34
注册 2006-4-5
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
3楼的大哥不好意思,我原先没看懂,现在弄明白了,你的是可以执行的。但我现在还是不懂得如何去引用变量的值。我目的是想这样:
先在a.txt中读一行,然后在b.txt中搜索,如果没有这行的内容则添上去,有的话就略过。我发觉是我原先没有表达得准确。对不起。
另外,你提到可以用goto循环,我有点明白其中的思路,也就是先读取一行,然后针对性地跳到相应的程序段。但现在我的问题是我根本不知道如何才可以读取a.txt中的一行?
用FOR是读遍了才停的,我该怎么办?
先谢谢你啦
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!
|
|
2006-4-5 15:17 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
是啊,很多时候把问题描述清楚是很重要的,如果你不知道如何描述问题的解决步骤,就把你想做什么说清楚。
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.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2006-4-5 18:09 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
不是我不明白,而是这楼主变幻太快。。
呵呵,你的要求变化得大。。
不想用type的话那就试试findstr+type:
findstr /v /g:b.txt a.txt >>tmp.txt
type tmp.txt >> b.txt
未经测试,理论上行得通,我想这个方法相比前面的那个方法更适合你。
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.
|
|
2006-4-5 20:57 |
|
|
wang6610
银牌会员
    
积分 1246
发帖 488
注册 2003-11-11
状态 离线
|
|
2006-4-6 01:09 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
Re 3742668:
估计楼主的变量,并非指环境变量,而是指for的替换变量,这样就好理解了。
另外,你的代码确实富于技巧性,稍加修改即可用于提取文本中的指定行,是一个具有普遍意义的算法。
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-4-6 03:07 |
|
|
alfredhou
初级用户
 
积分 100
发帖 34
注册 2006-4-5
状态 离线
|
『第 21 楼』:
re:3742668
使用 LLM 解释/回答一下
RE:3742668
大哥,谢谢你!我测试过你的方法,事实证明是可行的!万分感谢!
此外,我在测试的时候遇到一些总是问题:
1) 如果a.txt和b.txt原先都是有内容的话,那运行第一次时结果是和预期目标一致的,但再运行多一次就不一致了。我后来发现是因为tmp.txt第一次是空的,而第二次则有内容了。于是我在你的代码后面加了一条:del tmp.txt
2)如果b.txt原先是全空没有内容的话,那么运行批处理之后它仍然是全空没有内容的,也就是说达不到预期的目标。当然,我可以事情加入一行毫不相干的内容,那就可以达到我的预期目标。但我觉得那不是正道。
请问你有什么更好的解决方法吗?
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?
|
|
2006-4-6 16:37 |
|
|
alfredhou
初级用户
 
积分 100
发帖 34
注册 2006-4-5
状态 离线
|
『第 22 楼』:
RE:willsort
使用 LLM 解释/回答一下
RE:willsort
版主你好!
你说稍加改造可以提取指定的行,可以予以明示吗?我是一个新手,实在想不出来怎么才可以实现这个目标?
findstr /v /g:b.txt a.txt >>tmp.txt
type tmp.txt >> b.txt
请告诉我改造后的代码吗?
谢谢
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
|
|
2006-4-6 16:42 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
寒一个先。
其实你想实现的东东几篇回贴里面都有了,只不过你没能把它们结合起来而已。
关于你的问题:
1) 这个不算问题。
2) 用set /p tmpvar=<b.txt来获得,然后用if defined tmpvar来判断是否为空
最后,再汗一个,willsort说的稍加改造并非指的是type+findstr的那段,而是前面的for,呵呵,建议你多翻翻老贴多运行command /?。
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 /?.
|
|
2006-4-6 18:34 |
|
|
ke
新手上路

积分 4
发帖 2
注册 2006-9-28
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
好帖,3742668版主真是热心!
Good post, Moderator 3742668 is really enthusiastic!
|
|
2006-10-2 17:08 |
|