批处理文件返回文本文件最后一行的旁边
我有一个文件,其中包含写入文本文件的文件比较的输出:比较文件 C:\LOGS\old.txt 和 C:\LOGS\NEW.TXT
***** C:\LOGS\old.txt
***** C:\LOGS\NEW.TXT
文件夹_thats_不同
*****
我需要拉出倒数第二行“folder_thats_ Different”并放入一个新字符串:文件夹包含一个不同的文件:folder_thats_ different
是的,我知道我可以使用另一种语言,但我现在只能使用批处理文件。
I have a file that contains the output of a file compare thats written to a text file:Comparing files C:\LOGS\old.txt and C:\LOGS\NEW.TXT
***** C:\LOGS\old.txt
***** C:\LOGS\NEW.TXT
folder_thats_different
*****
I need to pull out the next to last line "folder_thats_different" and put in a new string:folder contains a file that is different: folder_thats_different
Yes, I know I can use another language, but I'm stuck with batch files for now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试使用 for 循环读取它并获取当前行,并始终保存上一行
You can try to read it with a for-loop and take the current line, and always save the previous line
这是一个可以作为起点的示例。只需将
set command=
行中的文件名更改为适当的名称(或将命令替换为生成日志列表的任何内容)。当然,您可能想做的不仅仅是简单地回显找到的行。
Here's an example you can use as a starting point. Just change the filename in the
set command=
line to the appropriate name (or replace the command with whatever will gerneate the log listing).Of course, you'll probably want to do something other than simply echoing the found line.
第一个答案对我有用。我还在末尾添加了 2 行以允许其重复,这样我就可以观看活动日志文件,而无需关闭并重新打开它。我对《太空工程师》游戏中使用的模组进行了大量调试。
我的版本如下所示:
下面的行阻止批处理文件循环太快并停止密钥绕过。要更改以秒为单位的时间量,只需将数字“15”更改为您想要的任何值。要停止批处理文件,只需按 ctrl+c。
下面的行是我创建的批处理文件的名称,因此它会告诉 CMD 再次运行它。
The first answer works for me. I also added 2 lines after the end to allow it to repeat so I could watch an active log file without having to close and reopen it. I do a lot of debugging for the mods that are used in the game Space Engineers.
My version looks like this:
The line below stops the batch file from looping too fast and stop the key bypass. To change the amount of time in seconds just change the number "15" to anything you want. To stop the batch file just press ctrl+c.
The line below is the name of the batch file I made so it will tell CMD to run this again.