Skip to main content
added 116 characters in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

If you have zsh, that would be more easily and safely (and portably) done there:

autoload -Uz zmv zmv -n '(*-)[[:alnum:]]##_<->_<->(*.*)' '$1$2' 

(remove the -n (dry-run) if happy).

That's using shell globs (zsh ones with extendedglob enabled) instead of regular expressions though in terms of functionality you get the equivalent of extended regexps and more.

  • * is the usual matches any number of characters (or bytes if there are bytes not forming valid characters, one reason it's safer than (most) regexps
  • [[:alnum:]] is the standard matching by POSIX character class.
  • ## is one or more of previous atom (like + in ERE/PCRE).
  • <-> is any sequence of one or more ASCII decimal digits, like <1-10> but without bound.

zmv will do a few sanity checks before starting the renaming making it safer than the various variants of rename around.

If you have zsh, that would be more easily and safely (and portably) done there:

autoload -Uz zmv zmv -n '(*-)[[:alnum:]]##_<->_<->(*.*)' '$1$2' 

(remove the -n (dry-run) if happy).

That's using shell globs (zsh ones with extendedglob enabled).

  • * is the usual matches any number of characters (or bytes if there are bytes not forming valid characters, one reason it's safer than (most) regexps
  • [[:alnum:]] is the standard matching by POSIX character class.
  • ## is one or more of previous atom (like + in ERE/PCRE).
  • <-> is any sequence of one or more ASCII decimal digits, like <1-10> but without bound.

zmv will do a few sanity checks before starting the renaming making it safer than the various variants of rename around.

If you have zsh, that would be more easily and safely (and portably) done there:

autoload -Uz zmv zmv -n '(*-)[[:alnum:]]##_<->_<->(*.*)' '$1$2' 

(remove the -n (dry-run) if happy).

That's using shell globs (zsh ones with extendedglob enabled) instead of regular expressions though in terms of functionality you get the equivalent of extended regexps and more.

  • * is the usual matches any number of characters (or bytes if there are bytes not forming valid characters, one reason it's safer than (most) regexps
  • [[:alnum:]] is the standard matching by POSIX character class.
  • ## is one or more of previous atom (like + in ERE/PCRE).
  • <-> is any sequence of one or more ASCII decimal digits, like <1-10> but without bound.

zmv will do a few sanity checks before starting the renaming making it safer than the various variants of rename around.

added 579 characters in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

If you have zsh, that would be more easily and safely (and portably) done there:

autoload -Uz zmv zmv -n '(*-)[[:alnum:]]##_<->_<->(*.*)' '$1$2' 

(remove the -n (dry-run) if happy).

That's using shell globs (zsh ones with extendedglob enabled).

  • * is the usual matches any number of characters (or bytes if there are bytes not forming valid characters, one reason it's safer than (most) regexps
  • [[:alnum:]] is the standard matching by POSIX character class.
  • ## is one or more of previous atom (like + in ERE/PCRE).
  • <-> is any sequence of one or more ASCII decimal digits, like <1-10> but without bound.

zmv will do a few sanity checks before starting the renaming making it safer than the various variants of rename around.

If you have zsh, that would be more easily and safely (and portably) done there:

autoload -Uz zmv zmv -n '(*-)[[:alnum:]]##_<->_<->(*.*)' '$1$2' 

(remove the -n (dry-run) if happy).

If you have zsh, that would be more easily and safely (and portably) done there:

autoload -Uz zmv zmv -n '(*-)[[:alnum:]]##_<->_<->(*.*)' '$1$2' 

(remove the -n (dry-run) if happy).

That's using shell globs (zsh ones with extendedglob enabled).

  • * is the usual matches any number of characters (or bytes if there are bytes not forming valid characters, one reason it's safer than (most) regexps
  • [[:alnum:]] is the standard matching by POSIX character class.
  • ## is one or more of previous atom (like + in ERE/PCRE).
  • <-> is any sequence of one or more ASCII decimal digits, like <1-10> but without bound.

zmv will do a few sanity checks before starting the renaming making it safer than the various variants of rename around.

Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

If you have zsh, that would be more easily and safely (and portably) done there:

autoload -Uz zmv zmv -n '(*-)[[:alnum:]]##_<->_<->(*.*)' '$1$2' 

(remove the -n (dry-run) if happy).