I have some files with names like this:
01_dpm_gsi_182.sl5
02_dpm_devel_gsi_182.sl5
03_DPM_DSI_181.sl5
04_globus_httpd_122.sl5
05_globus_httpd_client_cgi_132.sl5
How can I rename those files, so that I get some thing like:
01_dpmgsi_s2011e01.sl5
02_dpmdevelgsi_s2011e02.sl5
....
....
The closest I was suggested as like this:
#!/usr/bin/perl -n
if (/^([^_]+)_(.+)_([^.]+)([.].+)$/) {
my $s = $&;
my $x = $1;
my $y = $2;
my $z = 2011;
my $e = $4;
$y =~ s/_//g;
print "mv $s ${x}_${y}_s${z}e$x$e\n"
}
and then use it like this:
# ls | perl -n reName.pl > output
# bash ./output
Is there any better way or one-liner to do this, possibly using sed/awk? Cheers!!