Rename the multiple files

Hi

I need to reanme the multiple file using unix script

I have multiple file

like:

sample_YYYYMMDD.xls
test new_YYYYMMDD.xls
simple_YYYYMMDD.xls

I need to rename this file

sample.xls
testnew.xls
SIMPLE.xls

thanks

does this help?

 echo "sample_YYYYMMDD.xls
test new_YYYYMMDD.xls
simple_YYYYMMDD.xls"|awk '{a="mv "$0" "; gsub(/_.*xls/,".xls",$0);a=a$0; print a}'|sh

you can change the echo part with your own find/ls command

Please use code tags when pasting code or sample input/output.

On most linux distros, there is a utility, called 'rename' that does the job.
However, I am aware of two different implementations, so check 'man rename' and make a test on copies of the files first, before you actually rename them all.
On redhat/centos systems the syntax would be

rename "_[0-9]*" "" *.xls

on debian/Ubuntu, the syntax is perl-like

rename 's/_[0-9]*//' *.xls

The second variant is sometimes called 'prename' (perl rename) on some systems. Again, check the man pages.

rename "_[0-9]*" "" *.xls

can you please explace above post where i need to use this

just type it in the terminal in the directory with the files you want to rename.

Type

rename --help

If you see something like

Usage: rename [-v] [-n] [-f] perlexpr [filenames]

, then you have the second mentioned version of rename.
Type

rename -n  's/_[0-9]*//' *.xls

Which will not rename anything, just do a dry-run and tell you what it would do. If you are happy, just run it wihtout the -n switch.

modification source fole format

I have receive the file below format

2010_simple_test_20100912.xls
2010_information_new_20100912.xls

I need to rename the above two file in below format

simple.xls
information.xls

can you please guide me on this

rename(1) is your best bet. I still don't know what version of rename you have, though.

If the above worked for you, why don't you just use it twice?

rename 's/^[0-9]*_//' *.xls   #will strip the leading numbers and underscore
rename 's/_[0-9]*//' *.xls    #strip the underscore followed by number

Another one,

 
ls -1 | sed 's/\(.*\)_.*/mv & \1.xls/g' | sh

im in the same boat, but having issues because the system re-names the files with wild card characters when it gets moved to history...

Origional File Name:
110726000053699.850

When it goes into history:
110726000053699.850*15913*34969.7527

i have 56 files for 1 day like this, and i need to pull them out of history, and remove all of the info after 850 :wall: