![]() |
|
|
|
|
|||||||
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Renaming multiple files | jayell | Shell Programming and Scripting | 5 | 02-27-2008 12:17 PM |
| Removing certain text from multiple filenames | Djaunl | UNIX for Dummies Questions & Answers | 6 | 01-15-2008 01:52 PM |
| Renaming of multiple filenames | shashi_kiran_v | UNIX for Dummies Questions & Answers | 4 | 07-11-2005 04:57 AM |
| Renaming multiple files | rmayur | UNIX for Dummies Questions & Answers | 6 | 02-26-2004 12:40 AM |
| renaming multiple files | piltrafa | UNIX for Dummies Questions & Answers | 6 | 11-10-2001 08:27 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Renaming of multiple filenames
Hi All,
I need to rename the file names. I need to rename for example as follows file001 to flat1 file100 to flat100 Thanks Shash |
| Forum Sponsor | ||
|
|
|
|||
|
Try this
#! /bin/ksh
i=0 for list in `ls -l file*` do if [ $i -lt 99 ] then tmp=`echo $list| sed "s/^[a-z]*[0-9]*$/flat$i/"` mv path_to_dir/$i path_to_dir/$tmp i=$((i+1)) ; fi tmp=`echo $list| "sed s/^\([a-z]\)\([0-9]*\)/flat\2/"` mv path_to_dir/$i path_to_dir/$tmp done < /tmp/files.txt ( not tested ) |
|
|||
|
hi,
you can try this, as far i had tested it works, plz let me know if there are any errors or anything to be clarified ----------------------------------------------------- for i in `ls flat*` do echo $i > cls val=`awk '{print substr($i,length($i)-2,3);}' cls` mv $i file`expr $val + 0` done rm -f cls exit 0 ----------------------------------------------------- |
|
||||
|
Quote:
Is it not for i in `ls file*` ?? |