我想计算文件中所有重复出现的次数。例如:
hellohello (this is counted)
hello (not conted)
我试过这段代码:
directory=`find ${dir} -type f`
for file in $directory
do
o=`egrep 'hello{2,2}' $file`
done
但它不起作用,我不明白为什么。
最佳答案
参见 http://mywiki.wooledge.org/ParsingLs为什么for file in $(find ...)
不好。
至于主要问题虽然意识到{2,2}
(以及所有其他修饰符)适用于模式中最近的原子,并且字符本身就是一个原子,所以你写的是
h
+ e
+ l
+ l
+ o{2,2}
这不是你想要的。
你想要hello
成为一个原子,所以组是:(hello){2,2}
.
关于regex - 在一个文件中出现 Bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30877104/