How to change file names from notation like this: SomeCodeFile.extension to C/C++ notation: some_code_file.extension. I’d like to use Perl + Find + Regex to print those names.
Advertisement
Answer
You can use a regular expression:
perl -e 'for $f (@ARGV) {
($n = $f) =~ s/(?<=.)([[:upper:]])/_l$1/g;
rename $f, lcfirst $n;
}' SomeCodeFiles*
[[:upper:]]matches upper case letters.(?<=.)is a look behind assertion, i.e. the letter is preceded by something (we don’t want_some_code_file.ext)lchanges the following letter to lowercase (similarly tolcfirst)
Note that the result might be unpleasant in some situations (x_m_l2_j_s_o_n.c, u_r_l__validator.cpp).