Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 发生在文件Bash中_Regex_Linux_Bash_Unix - Fatal编程技术网

Regex 发生在文件Bash中

Regex 发生在文件Bash中,regex,linux,bash,unix,Regex,Linux,Bash,Unix,我想计算一个文件中所有重复出现的次数。例如: hellohello (this is counted) hello (not conted) 我尝试了以下代码: directory=`find ${dir} -type f` for file in $directory do o=`egrep 'hello{2,2}' $file` done 但是它不起作用,我也不明白为什么。请参阅为什么$(find…)中的文件不好 至于主要问题,请注意,{2,2}(以及所有其他修饰符)适用于模

我想计算一个文件中所有重复出现的次数。例如:

hellohello (this is counted)
hello (not conted)
我尝试了以下代码:

directory=`find ${dir} -type f`

for file in $directory
do

    o=`egrep 'hello{2,2}' $file`
done
但是它不起作用,我也不明白为什么。

请参阅为什么$(find…)中的文件不好

至于主要问题,请注意,
{2,2}
(以及所有其他修饰符)适用于模式中最近的原子,并且字符本身就是原子,因此您所写的是

h
+
e
+
l
+
l
+
o{2,2}

这不是你想要的


您希望
hello
成为一个原子,所以组是:
(hello){2,2}

是的,现在它计算行数和单词数