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 7 01-12-2009 04:27 PM
Removing certain text from multiple filenames Djaunl UNIX for Dummies Questions & Answers 6 01-15-2008 05:52 PM
Renaming of multiple filenames shashi_kiran_v UNIX for Dummies Questions & Answers 4 07-11-2005 08:57 AM
Renaming multiple files rmayur UNIX for Dummies Questions & Answers 6 02-26-2004 04:40 AM
renaming multiple files piltrafa UNIX for Dummies Questions & Answers 6 11-10-2001 12:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-28-2005
shashi_kiran_v shashi_kiran_v is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 40
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
  #2 (permalink)  
Old 06-28-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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
  #3 (permalink)  
Old 06-28-2005
rahul123_libra rahul123_libra is offline
Registered User
  
 

Join Date: May 2005
Posts: 46
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 )
  #4 (permalink)  
Old 06-28-2005
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
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
-----------------------------------------------------
  #5 (permalink)  
Old 06-28-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
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*` ??
  #6 (permalink)  
Old 06-29-2005
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
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
  #7 (permalink)  
Old 06-28-2005
locustfurnace locustfurnace is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2004
Posts: 232
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" *.*
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0