Storing part of a filename as a variable
Hi All,
I'm writing a simple bash shell script in which I need to store part of a filename as a variable. I have seen a number of posts about how to append an environment variable to a filename, but not the other way around. What I'd like to do is the following:
Using a for-loop structure, I want to extract numbers from filenames, i.e.:
file_1.txt
file_2.txt
file_3.txt
...
file_1000.txt
Each time I extract the number, I want to use it in a simple calculation, then discard the variable value in favor of the next file in the series. So, run a calculation using 1 as the value, then run calculation with 2, 3, etc., for the entire series of file_*.txt. I hope that makes sense.
Can someone point me in the right direction? I am figuring it might take some crafty use of sed or grep, or some such tool, but I haven't been able to suss it out for myself.
Thanks in advance!
|