如何使用 findstr 或 grep 命令在文本文件中查找指定长度的字符串?
How to find a string with specified length in a text file using findstr or grep command?
我想在文本文件中查找以字符 "alo" 开头的长度为 8 的字符串。
对于 findstr,我尝试了以下命令 - findstr /R "\<alo" file.txt
。此命令搜索以"alo"开头的字符串,但搜索不到长度为8的字符串。对于grep,我不知道该怎么做。
grep -E '^alo(.*){5}$' filename
grep -woE 'alo.{5}' filename
-o 仅打印匹配
-E 是使用扩展正则表达式
-w 将使给定的表达式只匹配整个单词
括号内的数字指定字母后要匹配的字符数'alo'
我想在文本文件中查找以字符 "alo" 开头的长度为 8 的字符串。
对于 findstr,我尝试了以下命令 - findstr /R "\<alo" file.txt
。此命令搜索以"alo"开头的字符串,但搜索不到长度为8的字符串。对于grep,我不知道该怎么做。
grep -E '^alo(.*){5}$' filename
grep -woE 'alo.{5}' filename
-o 仅打印匹配
-E 是使用扩展正则表达式
-w 将使给定的表达式只匹配整个单词
括号内的数字指定字母后要匹配的字符数'alo'