I have files like ABC_asd_f.txt, DEF_qwe_r.txt, ...
How can I exchange the uppercases before the first underscore with the lowercases after? So ABC_asd_f.txt becomes asd_f_ABC.txt, DEF_qwe_r.txt becomes qwe_r_DEF.txt, ...
I have files like ABC_asd_f.txt, DEF_qwe_r.txt, ...
How can I exchange the uppercases before the first underscore with the lowercases after? So ABC_asd_f.txt becomes asd_f_ABC.txt, DEF_qwe_r.txt becomes qwe_r_DEF.txt, ...
Use perl rename. Firstly use the -n flag for a dry-run.
rename -n 's/^(...)_(..._.)/$2_$1/' *
Then, if you are happy, run it for real.
rename 's/^(...)_(..._.)/$2_$1/' *
This uses capturing groups.
rename 's/foo/bar/' *: replace foo with bar for all files *.^(...)_(..._.): from the beginning of the line ^, capture the first three characters (...), skip over _, then capture the next five characters, where the fourth is underscore (..._.).$2_$1: replace the string above with the capturing groups reversed (i.e. the second, an underscore, then the first).There are two renames in Linux-land. You can tell if it's perl rename with the following
$ rename --version
perl-rename 1.9
The other one will give a different result.
$ rename --version
rename from util-linux 2.28