![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-12 15:39 |
共 47,811 主题排行 / 349,897 发帖 / 今日 0 篇 / 48,256 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » findstr的bug,还是我没用对? |
| 可打印版本 1,087 / 12 |
| 第1楼 pillow | 发表于 2009-09-21 02:52 |
| 初级用户 发帖 82 积分 196 | |
|
findstr的bug,还是我没用对? 命令:
echo "10.128.227.33" | findstr "10.1." 结果: "10.128.227.33" 10.128也能匹配10.1.?? 请指教,谢谢~ |
|
| 第2楼 Hanyeguxing | 发表于 2009-09-21 03:12 |
| 银牌会员 发帖 897 积分 1,039 来自 在地狱中仰望天堂 | |
|
下表列出 findstr 接受的元字符。
字符 值 . 通配符:任何字符 * 重复:以前字符或类的零次或多次出现 ^ 行位置:行的开始 $ 行位置:行的结尾 字符类:集合中任何一个字符 反类:不在集合中的任何一个字符 \x 取消:元字符 x 的文字用途 \<xyz 字位置:字首 xyz> 字位置:字尾 所以,如果要搜索字符10.1.,应写成 echo "10.128.227.33" | findstr "10\.1\." [ Last edited by Hanyeguxing on 2009-9-21 at 03:20 ] |
|
| 第3楼 pillow | 发表于 2009-09-21 03:32 |
| 初级用户 发帖 82 积分 196 | |
|
但如命令所示,并没加“ /R Uses search strings as regular expressions.”这参数呀~
为什么要当成正则表达式来处理呢? |
|
| 第4楼 Hanyeguxing | 发表于 2009-09-21 03:44 |
| 银牌会员 发帖 897 积分 1,039 来自 在地狱中仰望天堂 | |
|
在findstr下是默认使用表达式的,不需要参数/r来开启。
/l的作用是将所有的表达式的元字符都作为普通字符,例如要搜索行首为10.1的字符,就必须写成findstr "^10\.1" 如果写成findstr /l "^10.1",那么^就不能成为行首元字符了。 换句话说,使用了l参数,就不能使用表达式了,因为没有元字符了。。。 [ Last edited by Hanyeguxing on 2009-9-21 at 04:13 ] |
|
| 第5楼 HAT | 发表于 2009-09-21 03:55 |
| 版主 发帖 5,017 积分 9,023 | |
|
Re 3楼 通配符和正则表达式没有必然的联系
|
|
| 第6楼 pillow | 发表于 2009-09-21 04:20 |
| 初级用户 发帖 82 积分 196 | |
|
惊讶!看了帮助文件,中文的和英文的:
正则表达式对应的不是Regular expression么? 在findstr的中文翻译这儿居然要做为“一般表达式”来解~ 在文件中寻找字符串。 FINDSTR filename] /B 在一行的开始配对模式。 /E 在一行的结尾配对模式。 /L 按字使用搜索字符串。 /R 将搜索字符串作为一般表达式使用。 /S 在当前目录和所有子目录中搜索 匹配文件。 /I 指定搜索不分大小写。 /X 打印完全匹配的行。 /V 只打印不包含匹配的行。 /N 在匹配的每行前打印行数。 /M 如果文件含有匹配项,只打印其文件名。 /O 在每个匹配行前打印字符偏移量。 /P 忽略有不可打印字符的文件。 /OFF 不跳过带有脱机属性集的文件。 /A:attr 指定有十六进位数字的颜色属性。请见 "color /F:file 从指定文件读文件列表 (/ 代表控制台)。 /C:string 使用指定字符串作为文字搜索字符串。 /G:file 从指定的文件获得搜索字符串。 (/ 代表控制台 /D:dir 查找以分号为分隔符的目录列表 strings 要查找的文字。 filename 指定要查找的文件。 除非参数有 /C 前缀,请使用空格隔开搜索字符串。 例如: 'FINDSTR "hello there" x.y' 在文件 x.y 中寻找 "h "there" 。 'FINDSTR /C:"hello there" x.y' 文件 x.y 寻 "hello there"。 一般表达式的快速参考: . 通配符: 任何字符 * 重复: 以前字符或类别出现零或零以上次数 ^ 行位置: 行的开始 $ 行位置: 行的终点 字符类别: 任何在字符集中的字符 补字符类别: 任何不在字符集中的字符 范围: 在指定范围内的任何字符 \x Escape: 元字符 x 的文字用法 \<xyz 字位置: 字的开始 xyz\> 字位置: 字的结束 有关 FINDSTR 常见表达法的详细情况,请见联机命令参考。 Searches for strings in files. FINDSTR ] strings filename] /B Matches pattern if at the beginning of a line. /E Matches pattern if at the end of a line. /L Uses search strings literally. /R Uses search strings as regular expressions. /S Searches for matching files in the current directory and all subdirectories. /I Specifies that the search is not to be case-sensitive. /X Prints lines that match exactly. /V Prints only lines that do not contain a match. /N Prints the line number before each line that matches. /M Prints only the filename if a file contains a match. /O Prints character offset before each matching line. /P Skip files with non-printable characters. /OFF Do not skip files with offline attribute set. /A:attr Specifies color attribute with two hex digits. See "color /?" /F:file Reads file list from the specified file(/ stands for console). /C:string Uses specified string as a literal search string. /G:file Gets search strings from the specified file(/ stands for console). /D:dir Search a semicolon delimited list of directories strings Text to be searched for. filename Specifies a file or files to search. Use spaces to separate multiple search strings unless the argument is prefixed with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or "there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for "hello there" in file x.y. Regular expression quick reference: . Wildcard: any character * Repeat: zero or more occurances of previous character or class ^ Line position: beginning of line $ Line position: end of line Character class: any one character in set Inverse class: any one character not in set Range: any characters within the specified range \x Escape: literal use of metacharacter x \<xyz Word position: beginning of word xyz\> Word position: end of word For full information on FINDSTR regular expressions refer to the online Command Reference. |
|
| 第7楼 Hanyeguxing | 发表于 2009-09-21 04:24 |
| 银牌会员 发帖 897 积分 1,039 来自 在地狱中仰望天堂 | |
|
在帮助和支持中心,译作常规表达式
hh.exe ms-its:C:\WINDOWS\Help\ntcmds.chm::/findstr.htm |
|
| 第8楼 HAT | 发表于 2009-09-21 04:38 |
| 版主 发帖 5,017 积分 9,023 | |
|
Re 6楼 最好看英文版本的,中文翻译简直是一坨屎,哦,对不起,是两坨。
|
|
| 第9楼 pillow | 发表于 2009-09-21 05:54 |
| 初级用户 发帖 82 积分 196 | |
|
就算是/R,也沒將pattern當作“一般表達式”來對待啊!~
echo "10.128.227.33" | findstr /r "10.1." 的結果仍是會返回 10.128.227.33 |
|
| 第10楼 Hanyeguxing | 发表于 2009-09-21 07:48 |
| 银牌会员 发帖 897 积分 1,039 来自 在地狱中仰望天堂 | |
|
不要管那些帮助里怎么翻译的,翻译成什么表达式
1,无论是否使用了/r参数,表达式都是被启用的,即.被作为通配符。 2,如果想使.不作为通配符号,以你的示例,可以写成: echo "10.128.227.33" | findstr /c:"10.1." echo "10.128.227.33" | findstr /l "10.1." echo "10.128.227.33" | findstr "10\.1\." echo "10.128.227.33" | findstr /r "10\.1\." [ Last edited by Hanyeguxing on 2009-9-21 at 08:17 ] |
|
| 第11楼 Hanyeguxing | 发表于 2009-09-21 08:04 |
| 银牌会员 发帖 897 积分 1,039 来自 在地狱中仰望天堂 | |
Originally posted by HAT at 2009-9-21 04:38: ms-its:C:\WINDOWS\Help\ntcmds.chm::/set.htm 中的一段,我当时就崩溃了... 数值是指十进制的数字,在前缀加 0× 则表示十六进制数字,加 0 则表示八进制数字。因此,0×2 与 18 相同,也与 022 相同,八进制表示法容易引起混淆。例如,08 和 09 不是有效数字,因为 8 和 9 不是有效的八进制数字。 |
|
| 第12楼 pillow | 发表于 2009-09-21 21:59 |
| 初级用户 发帖 82 积分 196 | |
|
看了11樓的引用,終於明白什麼是越解釋越亂~
原findstr的理解又多了些,謝謝11樓耐心的說明~ |
|
| 第13楼 Evangel | 发表于 2009-09-30 21:29 |
| 初级用户 发帖 95 积分 145 | |
Originally posted by Hanyeguxing at 2009-9-21 08:04 AM: 0X2应该是十进制的2吧……0X12才是18吧…… |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |