I’ve got the following files:
create_file_1.sql
create_file_2.sql
create_file_3.sql
create_file_4.sql
I’m iterating those files in a loop.
Now I want to get the number inside those files. I want to store the 1, 2, 3, … inside a variable in the loop.
How can I achieve this? How can I cut out this number?
P. S.: I want to achieve this with an AIX command.
Well … It depends on how flexible you want it to be. If you can assume that the number is “the part between the second underscore and the first period after the second underscore”, you can simply use:
assuming that
$FILENAMEholds the current filename, of course.This uses
cutto first take the string after the second underscore, then cutting that by taking the string leading up to the first period.This, admittedly, does not use regular expressions which maybe you want based on your tags, but I find the above a bit easier to read for a simple case like this.