regex - Unix: Rename file with dynamic extension -
i using rhel 5.10 , trying remove dynamic date extension bunch of files.
the file format filename01.gz.20160704
, last part date
dynamic. want renamed filename01.gz
when try rename below, works
rename gz.20160704 gz filename01.gz.20160704
output: filename01.gz
but when try rename doesn't work
rename gz.* gz filename01.gz.20160704
i tried searching other answer , in of them, used rename below, sadly not working me.
rename 's/gz*/gz/' filename01.gz.20160704 rename 's/gz.*/gz/' filename01.gz.20160704
the man
page linux says
for example, given files foo1, ..., foo9, foo10, ..., foo278, commands rename foo foo0 foo? rename foo foo0 foo??
could please me or there alternative approach can use?
update: added solution given @pskocik not working either.
$> ls -ltr filename01* -rw-rw----+ 1 foo foo 0 jul 4 08:34 filename01.gz.20160704 $> rename -n 's/\.gz\.[^.]*/.gz/' filename01.gz.* $> echo $? 0 $> ls -ltr filename01* -rw-rw----+ 1 foo foo 0 jul 4 08:34 filename01.gz.20160704
with
prename
(perl-rename):rename -n 's/\.gz\.[^.]*/.gz/' filename01.gz.*
with mv , posix shell:
for f in *.gz.*; mv "$f" "${f%.*}"; done
Comments
Post a Comment