Operating System - HP-UX
1753488 Members
4379 Online
108794 Solutions
New Discussion юеВ

Re: script to rename multiple file names

 
gab_in
Regular Advisor

script to rename multiple file names

Hi,

I have a directory which has filenames with extension .amt;1 (e.g one file name is sgho11.amt;1 and another filename is sgho12.amt;1). Can you please let me know how can I rename all the files with extension .amt1.

Thanks in advance
Gab
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: script to rename multiple file names

Shalom Gab,

Side note: Looks like wherever you got these files you didn't mount the media properly.

I'm not sure after the rename you will have usable files. It might be better to properly mount the media and copy the files to disk properly.

ls -1 > list

while read -r fn
do
# add a line to calculate the new name.
mv $fn $newname
done < list
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: script to rename multiple file names

sen_ux
Valued Contributor

Re: script to rename multiple file names

Hi Gab,

Please try below.

for file in `ls -1`
> do
> mv $file `echo $i|awk -F. '{print $1}'`.amt1
> done


Thanks
Sen
Tingli
Esteemed Contributor

Re: script to rename multiple file names

Or,

for i in $(ls)
do
mv $i ${i%%;1}1
done
Dennis Handly
Acclaimed Contributor

Re: script to rename multiple file names

>ME: You are going to have to quote $fn since it has a ";":

Oops, it appears the shell scans for ";" before it does parm substitution. So only whitespace needs to be quoted.