How can I search for a string in a filename? For example, I want to know if a filename (not the file contents) contains the string "test".
for i in *
do
echo "$i" | grep -q 'test' && echo "$i has the word test in it"
done
basically echo the filename thru a pipe to grep.
In what language?
Assuming bourne shell, how about:
expr index filename len >/dev/null && echo ok
js.
Just 1 file name? Is this sufficient?
$> echo somefilename| awk '/test/ {print "yo"}'
$> echo sometestfilename| awk '/test/ {print "yo"}'
yo