I have a few thousand files named as follows:
Cyprinus_carpio_600_nanopore_trim_reads.fasta
Cyprinus_carpio_700_nanopore_trim_reads.fasta
If you can get hold of the Perl-flavoured version of rename
, that is simple like this:
rename -n 's/(\d+)/$1 + 100/e' *fasta
Sample Output
'Ciprianus_maximus_11_fred.fasta' would be renamed to 'Ciprianus_maximus_111_fred.fasta'
'Ciprianus_maximus_300_fred.fasta' would be renamed to 'Ciprianus_maximus_400_fred.fasta'
'Ciprianus_maximus_3900_fred.fasta' would be renamed to 'Ciprianus_maximus_4000_fred.fasta'
If you can't read Perl, that says... "Do a single substitution as follows. Wherever you see a bunch of digits next to each other in a row (\d+
), remember them (because I put that in parentheses), and then replace them with the evaluated expression of that bunch of digits ($1
) plus 100.".
Remove the -n
if the dry-run looks correct. The only "tricky part" is the use of e
at the end of the substitution which means evaluate the expression in the substitution - or I call it a "calculated replacement".