The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2005
Registered User
 

Join Date: Jun 2005
Posts: 40
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-28-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,628
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by shashi_kiran_v
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

Will your filename always end with 3 digits ?

Vino
Reply With Quote
  #3 (permalink)  
Old 06-28-2005
Registered User
 

Join Date: May 2005
Posts: 46
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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 )
Reply With Quote
  #4 (permalink)  
Old 06-28-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,404
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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
-----------------------------------------------------
Reply With Quote
  #5 (permalink)  
Old 06-28-2005
Registered User
 

Join Date: Aug 2004
Posts: 232
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by shashi_kiran_v
file001 to flat1
file100 to flat100


Can also use the rename command.

rename "file00" "flat" *.*
rename "file" "flat" *.*
Reply With Quote
  #6 (permalink)  
Old 06-28-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by matrixmadhan
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
-----------------------------------------------------

Is it not for i in `ls file*` ??
Reply With Quote
  #7 (permalink)  
Old 06-28-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,404
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
that was a confusion

to rename from file* to flat* or
flat* or file*

anyway that was a good catch

i should have been even more careful


thanks
Reply With Quote
  #8 (permalink)  
Old 07-05-2005
Registered User
 

Join Date: Jun 2005
Posts: 40
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Sorry for the delay in responding to your mail. Thank you so much.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101