我想从txt文件中查找特定字符
早上好,我想从txt文件中查找特定字符并创建一个新的txt文件。该文件包含以下行:
Server: http://esv5.net:80/c/
MAC: 00:1a:79:17:52:ae
Vence:February 28, 2022, 11:35 pm
http://mag.abcdxyz.one/c
00:1a:79:d6:3f:2a;January 4, 2023, 3:17 pm
00:1a:79:2e:e7:e1;July 30, 2022, 12:18 pm
....
....
我希望以相同的顺序输出:
http://esv5.net:80/c/
00:1a:79:17:52:ae
http://mag.abcdxyz.one/c
00:1a:79:d6:3f:2a
00:1a:79:2e:e7:e1
我的批处理代码是:
@echo off
FIND "http://" "C:\Users\dom19\Downloads\file.txt"
FIND "00:1a:79" "C:\Users\dom19\Downloads\file.txt"
TYPE C:\Users\dom19\Downloads\file.txt > C:\Users\dom19\Downloads\Newfile.txt
pause
我添加此命令来保存结果而不是保存: <代码>> C:\Users\dom19\Desktop\results.txt 它就是这样工作的
C:\Users\dom19\Desktop\script.bat >> "C:\Users\dom19\Desktop\file.txt"
Good morning, I want to find specific characters from txt file and create a new txt file. The file contain this lines:
Server: http://esv5.net:80/c/
MAC: 00:1a:79:17:52:ae
Vence:February 28, 2022, 11:35 pm
http://mag.abcdxyz.one/c
00:1a:79:d6:3f:2a;January 4, 2023, 3:17 pm
00:1a:79:2e:e7:e1;July 30, 2022, 12:18 pm
....
....
I want this output in same order:
http://esv5.net:80/c/
00:1a:79:17:52:ae
http://mag.abcdxyz.one/c
00:1a:79:d6:3f:2a
00:1a:79:2e:e7:e1
My batch code is:
@echo off
FIND "http://" "C:\Users\dom19\Downloads\file.txt"
FIND "00:1a:79" "C:\Users\dom19\Downloads\file.txt"
TYPE C:\Users\dom19\Downloads\file.txt > C:\Users\dom19\Downloads\Newfile.txt
pause
I add thiss command to save results bat not save:> C:\Users\dom19\Desktop\results.txt
it just works like that
C:\Users\dom19\Desktop\script.bat >> "C:\Users\dom19\Desktop\file.txt"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
读取每一行,使用空格和冒号作为分隔符,选择第一个标记(到
%%b
),并将该行的其余部分(标记*
)选择到%%c
。对于
Server
和MAC
行,仅对以
http
开头的行回显%%c
,同时回显两个%%b
和%%c
,重新插入冒号。对于以
00
开头的行,检查该行的其余部分是否以1a:79:
开头,如果是,则使用重新标记该行的其余部分;
作为分隔符。仅选择第一个标记(默认),并回显
00
、冒号以及;
之前的行部分。抱歉,我不清楚输出文件的要求。数据将简单地
回显
到屏幕上。您没有提供任何有关如何判断所需数据何时完整的信息,因此我无法为您提供终止批处理的代码。Read each line, using both spaces and colons as delimiters, selecting the first token (to
%%b
) and the rest of the line (token*
) to%%c
.For the lines
Server
andMAC
, echo%%c
onlyfor lines starting
http
, echo both%%b
and%%c
, re-inserting the colon.for lines that start
00
, check whether the remainder of the line starts1a:79:
and if it does, then retokenise the rest-of-line using;
as a delimiter. Select the first token only (default), andecho
the00
, a colon and the part of the line that precedes the;
.I'm sorry, but I'm not clear on the requirement for the output file. The data will simply be
echo
ed to the screen. You've not provided any information on how to tell when the data you want is complete, so I can't provide you with code to terminate the batch.