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
moving and renaming multiple files rocinante Shell Programming and Scripting 1 06-07-2007 05:20 PM
Renaming multiple files rmayur UNIX for Dummies Questions & Answers 6 02-26-2004 12:40 AM
Renaming multiple files jxh461 Shell Programming and Scripting 4 04-01-2003 03:25 PM
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 09-20-2007
Registered User
 

Join Date: Jul 2006
Posts: 16
Stumble this Post!
Multiple Files Renaming with space

Hi,

I need help how to renaming multiple file. The original file look like this;

Test Monday.txt
Test Wednesday.txt
Test July.txt

I have more than hundred file in the directory.

How i want to rename all file to a new file name in one time? The new file maybe the same name e.g. TestMonday.txt OR different file name e.g. Test MondayJuly.txt
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-20-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,323
Stumble this Post!
You will have to run a loop that goes over all the files in the directory one at a time, because you can only rename one file in one mv command.

If you want to do this, you will have to establish some logic that can translate your current name to your new name. That means that all files will be renamed in a similar manner (removing the spaces in the filename, for instance).
Reply With Quote
  #3 (permalink)  
Old 09-20-2007
Registered User
 

Join Date: Jul 2006
Posts: 16
Stumble this Post!
i still can't get it. Maybe i give another example, i have original file as below;

Test Fish#10125#STAR.txt
Test Fish#52134#MOON.txt
Test Fish#32598#CLOUD.txt
Test Fish#66789#STORM.txt

I need to remove the space between "Test Fish" but i want to do one time for all file before i encrypt it.

After i encrypt the file, the file name will become TestFish#10125#STAR_encrypted.txt ... so i need to change back to original file name also in one time for all files.

Does anyone know how to do this or know what ‘functions’ I should use???
Reply With Quote
  #4 (permalink)  
Old 09-21-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,536
Stumble this Post!
With the Z-Shell:

Code:
zsh 4.3.4% touch Test\ Fish#10125#STAR.txt Test\ Fish#52134#MOON.txt Test\ Fish#32598#CLOUD.txt Test\ Fish#66789#STORM.txt
zsh 4.3.4% autoload -U zmv                                                                                                
zsh 4.3.4% zmv  '*' '${f// /}'                                                                                            
zsh 4.3.4% ls
TestFish#10125#STAR.txt  TestFish#32598#CLOUD.txt  TestFish#52134#MOON.txt  TestFish#66789#STORM.txt
zsh 4.3.4% zmv  '*' '$f:r_encrypted.txt'                                                                                 
zsh 4.3.4% ls
TestFish#10125#STAR_encrypted.txt   TestFish#52134#MOON_encrypted.txt
TestFish#32598#CLOUD_encrypted.txt  TestFish#66789#STORM_encrypted.txt
zsh 4.3.4% zmv  '*' '${f//_encrypted/}' 
zsh 4.3.4% ls
TestFish#10125#STAR.txt  TestFish#32598#CLOUD.txt  TestFish#52134#MOON.txt  TestFish#66789#STORM.txt
Reply With Quote
  #5 (permalink)  
Old 09-21-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
A simpler way,

Code:
ls Test* | while read file
do
mv "$file" `echo "$file" | sed 's/ //'`
done
Reply With Quote
  #6 (permalink)  
Old 09-21-2007
Registered User
 

Join Date: Jul 2006
Posts: 16
Stumble this Post!
i like a simpler way...thanxs a lot. It work for me. I have a lot a files to rename and if i want to rename the file name from

1) TestFish_done.txt to Test Fish Done.txt,

And

2) FishOne_done.txt to FishOne.txt, then how?

Last edited by nazri76; 09-22-2007 at 12:05 AM.
Reply With Quote
  #7 (permalink)  
Old 09-22-2007
kamitsin's Avatar
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Stumble this Post!
Case1: TestFish_done.txt to Test Fish Done.txt,

Code:
#!/bin/ksh
for oldfile in $(find . -name TestFish*)
do
   newfile="$(echo $oldfile | sed 's/Test/Test /g'|sed 's/\_/ /g')"
   mv "$oldfile" "$newfile"
done
Case2: FishOne_done.txt to FishOne.txt

Code:
#!/bin/ksh
for oldfile in $(find . -name FishOne*)
do
   newfile="$(echo $oldfile | sed 's/_done//g')"
   mv "$oldfile" "$newfile"
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:15 PM.


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