regex - Change file names by Perl -


how change file names notation this: somecodefile.extension c/c++ notation: some_code_file.extension. i'd use perl + find + regex print names.

you can use regular expression:

perl -e 'for $f (@argv) {              ($n = $f) =~ s/(?<=.)([[:upper:]])/_\l$1/g;              rename $f, lcfirst $n;          }' somecodefiles* 
  • [[:upper:]] matches upper case letters.
  • (?<=.) behind assertion, i.e. letter preceded (we don't want _some_code_file.ext)
  • \l changes following letter lowercase (similarly lcfirst)

note result might unpleasant in situations (x_m_l2_j_s_o_n.c, u_r_l__validator.cpp).


Comments