The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
moving and renaming multiple files rocinante Shell Programming and Scripting 1 06-07-2007 08:20 PM
Renaming multiple files rmayur UNIX for Dummies Questions & Answers 6 02-26-2004 04:40 AM
Renaming multiple files jxh461 Shell Programming and Scripting 4 04-01-2003 06:25 PM
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
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-20-2007
nazri76 nazri76 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 16
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
  #2 (permalink)  
Old 09-20-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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).
  #3 (permalink)  
Old 09-21-2007
nazri76 nazri76 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 16
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???
  #4 (permalink)  
Old 09-21-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
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
  #5 (permalink)  
Old 09-21-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,930
A simpler way,

Code:
ls Test* | while read file
do
mv "$file" `echo "$file" | sed 's/ //'`
done
  #6 (permalink)  
Old 09-22-2007
nazri76 nazri76 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 16
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 03:05 AM..
  #7 (permalink)  
Old 09-22-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
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
Sponsored Links
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 12:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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