I have several thousand files of the form:
[8-digit number]_[number I want]_S60491_I129111.dcm.
I wish to remove everything except the number I want, and use that as its name. In Ruby, I can get to that value with the regular expression
/^.*_(\d+)_S60491_I12911.dcm/, but I'm having trouble trying to translate that to a
sed expression that allows me to substitute the full filename for just that number between the underscores.
Is there a way using
sed or other basic Bash commands to do what I want? If it helps, the number I want is just a counter (i.e. it runs from 1 to 2100), and the prefix 8-digit number happens to result in the files being listed in correct order (i.e. from file 1 to file 2100), so I may be over-thinking things.