I’m looking to make a bash alias that will change the results of ls. I am constantly dealing with large sequences of files, that do not follow the same naming conventions. The only common thing about them is that the number is 4 padded (sorry not really sure of correct way to say that) and immediately precedes the extension.
eg – filename_v028_0392.bgeo, test_x34.prerun.0012.simdata, filename_v001_0233.exr
I would like for the sequences to be listed each as 1 element, so that
filename_v003_0001.geo
filename_v003_0002.geo
filename_v003_0003.geo
filename_v003_0004.geo
filename_v003_0005.geo
filename_v003_0006.geo
filename_v003_0007.geo
filename_v003_0032.geo
filename_v003_0033.geo
filename_v003_0034.geo
filename_v003_0035.geo
filename_v003_0036.geo
testxxtest.0057.exr
testxxtest.0058.exr
testxxtest.0059.exr
testxxtest.0060.exr
testxxtest.0061.exr
testxxtest.0062.exr
testxxtest.0063.exr
would be displayed as somethign along the lines of
[seq]filename_v003_####.geo (1-7)
[seq]filename_v003_####.geo (32-36)
[seq]testxxtest.####.exr (57-63)
while still listing non sequences unaltered.
I’m really not sure where to start approaching this. I know a decent amount of python, but not sure if that would really be the best way to go about it. Any help would be greatly appreciated!
Thanks
I got a python 2.7 script that solves your problem by solving the more general problem of collapsing several lines changing only by a sequence number
That is, on your data:
It bases itself on the differences between the integers present in two consecutive lines that match on the non-digit text. This allows to deal with non-uniform input, on changes of the field used as basis for the sequence…
Here is an example of input:
which gives:
Any comment is welcome!
Hah… I nearby forgot: without arguments, this script outputs the collapsed contents of the current directory.