Board logo

标题: [文本处理] 批处理命令findstr怎么返回指定字符串? [打印本页]

作者: 857185187    时间: 2020-10-25 12:33     标题: 批处理命令findstr怎么返回指定字符串?

findstr只能返回一整行,如果只返回满足正则表达式的字符串???
还是findstr没有这种功能?
作者: smss    时间: 2020-10-25 12:57

什么条件?
findstr/?自查
作者: 857185187    时间: 2020-10-25 14:18

回复 2# smss


    条件就是正则表达式,Findstr会返回一整行,而不是字符串
作者: qixiaobin0715    时间: 2020-10-25 17:06

回复 3# 857185187
没明白你的意思,希望下面的例子对你有所帮助

返回包含数字的行:
findstr [0-9] a.txt
返回纯数字行(不包括正负数和小数)及空行:
findstr /be "[0-9]*" a.txt
返回纯数字行(不包括正负数和小数):
findstr /be "[0-9][0-9]*" a.txt
作者: Batcher    时间: 2020-10-25 17:42

回复 1# 857185187


findstr本身没有这种功能
可以试试 grep.exe 命令行工具:
http://bcn.bathome.net/s/tool/index.html?key=grep
作者: Batcher    时间: 2020-10-25 17:45

回复 4# qixiaobin0715


比如有一行:
bbs.bathome.net
楼主需要的是仅返回某个字符串,比如 bathome
类似于 grep -o 可以实现的功能




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2