|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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........ |
|
#2
|
||||
|
||||
|
Check out the "renna" script at http://www.faqs.org/docs/Linux-HOWT...ntro-HOWTO.html
__________________
Alex (http://www.alex-greg.com) |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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.... |
|
#5
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Unix Script "File Change" |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|