我正在尝试编写一个脚本,使其允许我选择文件名中包含2个或更多相同字符串的文件。
例如:
test.txt // 1 occurrence only, not ok
test-test.txt // 2 occurrences OK
test.test.txt // 2 occurrences OK
我希望这个脚本只返回文件2和3。我尝试了这样做,但是没有成功:
rows=$(ls | grep "test")
for file in $rows
do
if [[ $(wc -w $file) == 2 ]]; then
echo "the file $file matches"
fi
done