UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 8th, 2003, 08:22 AM
trouble trouble is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ireland
Posts: 5 trouble User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post Unix Script "File Change"

Hi Guys,

I am looking for a script that will change a certain character of a file name. I have a bunch of files from a location i.e "wf95234red3"
and i want to change the file to "wf96234red3" just changing the 6 . What i need is to change lots of these at the same time.

All the files have different letters at the end but the first part is the same wf95.

Regards Trouble........

Reply With Quote
  #2  
Old August 15th, 2003, 07:09 PM
alexgreg's Avatar
alexgreg alexgreg is offline
Full Access
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2000
Location: London, UK
Posts: 2,019 alexgreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 sec
Reputation Power: 11
__________________
Alex
(http://www.alex-greg.com)

Reply With Quote
  #3  
Old August 16th, 2003, 05:49 PM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 33 m
Reputation Power: 10
A small shell script should do the trick if you only want to change the 5 to a 6 (run this in the same directory as the wf95* files):

Code:
#!/bin/sh
for file in `ls wf95*`
do
echo $file | sed -e 's/wf95\(.*\)/mv "&" wf96\1/' | sh
done


You might want to test it first by removing the '| sh' - it should output a list of 'mv' commands:

Code:
[23:47:22] root@users /root/tmp# ./tmp.sh
mv wf95234red3 wf96234red3


Even quicker you could just run the command from the commandline:
Code:
ls -1 wf95* | sed -e 's/wf95\(.*\)/mv "&" wf96\1/' | sh

again though make sure the command is outputting what it should by removing the |sh first.

Last edited by munkfish : August 17th, 2003 at 09:23 AM.

Reply With Quote
  #4  
Old August 18th, 2003, 04:46 AM
trouble trouble is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Ireland
Posts: 5 trouble User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Munkfish,

That works fine, But i have a further problem.

I will also need to change the same thing inside the file also.

Regards Barry....

Reply With Quote
  #5  
Old August 18th, 2003, 10:45 AM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 33 m
Reputation Power: 10
Use the -i switch to edit the file 'in place':

Code:
sed -i -e 's/wf95/wf96/g' wf96*


To change every occurrence of 'wf95' with 'wf96' everywhere it occurs on each line.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Unix Script "File Change"


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway