1
即時尋找一個bash腳本來算一個詞的出現次數在給定的目錄,它的這種模式子目錄中的文件:grep的多次出現給出了兩個字符串和兩個整數
^str1{n}str2{m}$
例如:
str1= yo
str2= uf
n= 3
m= 4
比賽將是 「yoyoyoufufufuf」
但我在使用grep麻煩
這就是我試過的
for file in $(find $dir)
do
if [ -f $file ]; then
echo "<$file>:<`grep '\<\$str1\{$n\}\$str2\{$m\}\>'' $file | wc -l >" >> a.txt
fi
done
我應該用find嗎?
對'grep'使用'-R'和'-c'選項進行遞歸而不使用'find'並計算沒有'wc'的匹配。 – Barmar