I had a similair post on this a few weeks back. But I didn't explain my requirements clearly then. Hence starting a new thread now.
I have lots of files in /tmp/stage directory as show below.
I want to loop through each files to run a command on each file.
I want to skip those files whose names end with a number. How can I do this ? My following attempts in writing the for loop has failed.
# touch sharp
# touch sharper
# touch sharpest
# touch sharpener
# touch sharpy
# touch sharper2
# touch sharpest4
# pwd
/tmp/stage
# ls -ld *
-rw-r--r--. 1 root root 0 Oct 8 03:12 sharp
-rw-r--r--. 1 root root 0 Oct 8 03:12 sharpener
-rw-r--r--. 1 root root 0 Oct 8 03:12 sharper
-rw-r--r--. 1 root root 0 Oct 8 03:14 sharper2
-rw-r--r--. 1 root root 0 Oct 8 03:12 sharpest
-rw-r--r--. 1 root root 0 Oct 8 03:14 sharpest4
-rw-r--r--. 1 root root 0 Oct 8 03:12 sharpy
#
# for i in /tmp/stage/sharp[a-b]* ; do echo $i ; done
/tmp/stage/sharp[a-b]*
#
#
#
# for i in /tmp/stage/sharp[a-b] ; do echo $i ; done
/tmp/stage/sharp[a-b]
#
#
# for i in /tmp/stage/sharp*[a-b] ; do echo $i ; done
/tmp/stage/sharp*[a-b]
#
I want this for loop to run a command on each file like
for f in /tmp/stage/sharp[a-z]
do
echo "Processing $f"
# do something on $f
done
At the risk of being pedantic, I will point out that the set of files not ending in a digit and the set of files ending with a letter may not be identical. Which is the correct set is left for the OP to decide.