Using regex with `rename` version from `util-linux` -


i’m using gnu/linux distribution utility rename comes util-linux , want make full use of regular (perl or posix) expressions it.

there two versions of rename :

  • the “perl” version, syntax rename 's/^fgh/jkl/' fgh*
  • the util-linux version, syntax rename fgh jkl fgh*

if use of regexes seems pretty obvious first one, have no easy access. however, i’m confused second one: not find relevant documentation or examples on possible use, , in case format, of regular expressions use.

let’s take, make simple example, directory containing:

foo_a1.ext foo_a32.ext foo_c18.ext foo_h12.ext 

i want use syntax 1 of these 2 lines:

rename "foo_[a-z]([0-9]{1,2}).ext" "foo_\1.ext" * rename "foo_[:alpha:]([:digit:]{1,2}).ext" "foo_\1.ext" * 

for expected output be:

foo_1.ext foo_32.ext foo_18.ext foo_12.ext 

of course not work! either i’m missing obvious, or there no implemented way use actual regular expressions tool.

(please note aware of other possibilities renaming files regular expressions in shell interpreter; question aims @ specific version of rename tool.)

here manual page: http://linux.die.net/man/1/rename. pretty straightforward:

rename from to file...

rename rename specified files replacing first occurrence of from in name to.

i believe there no regexes, plain substring match.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -