Occurring string in all filenames in a folder in Bash
I am trying to make a script that allows me to select files with 2 or more occurrences of a line in their name.
Example:
test.txt // 1 occurrence only, not ok
test-test.txt // 2 occurrences OK
test.test.txt // 2 occurrences OK
I want the script to only return files 2 and 3 to me. I tried this way but it didn't work:
rows=$(ls | grep "test")
for file in $rows
do
if [[ $(wc -w $file) == 2 ]]; then
echo "the file $file matches"
fi
done
+3
source to share