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}
是的,现在它计算行数和单词数