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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help with a 'while read' loop to change the names of files starsky Shell Programming and Scripting 6 03-01-2008 01:47 PM
Change All File Names in a Directory andou UNIX for Dummies Questions & Answers 8 01-22-2008 09:06 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 05:25 AM
Script to automatically change password. rahulrathod Shell Programming and Scripting 1 10-04-2004 08:33 AM
How would I telnet & change user password automatically in a script darthur UNIX for Dummies Questions & Answers 4 01-14-2002 11:40 AM

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

Join Date: Aug 2005
Posts: 3
How to change automatically the file names

Hi all,

I need to replace automatically all special characters of one filename with some corresponding characters

For example >

ö --> oe

ä --> ae

....

If the special character comes more than one time, then all the coccuerences have to be replaced.

I would like to have a acript, which could do the replacement through the whole file system.

Can somebody help me please

Thanks in advance

MAKY
  #2 (permalink)  
Old 08-10-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Try this.

Code:
#! /bin/sh

for file in `find /dir/to/search -name '*.*'`
do
PATH=${file%/*}
FILE_OLD=${file#$PATH}
FILE_NEW={FILE_OLD//<special-char>/<replacement>}
mv ${PATH}/${file} ${PATH}/${FILE_NEW}
done
Not tested tho'.

<special-char> is the char you wish to replace.
<replacement> is the replacement.

Vino

Last edited by vino; 08-10-2005 at 07:42 AM..
  #3 (permalink)  
Old 08-10-2005
MAKY MAKY is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 3
Vino, thanks for the quick reply, but I couldn't get any result yet.
I have written your script in the following form, making the test for replacing all the z letters with d letters


#! /bin/sh

for file in `find /tmp/ -name '*.*'`
do
PATH=${file%/*}
FILE_OLD=${file#$PATH}
FILE_NEW={FILE_OLD//<z>/<d>}
mv ${PATH}/${file} ${PATH}/${FILE_NEW}
done


The script doesn't give any error but also doesn't replace any charecters.

Thanks in advance
MAKY
  #4 (permalink)  
Old 08-10-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
#! /bin/sh

for file in `find /tmp/ -name '*.*'`
do
PATH=${file%/*}
FILE_OLD=${file#$PATH}
FILE_NEW=${FILE_OLD//z/d}
mv ${PATH}/${file} ${PATH}/${FILE_NEW}
done


vino

Last edited by vino; 08-10-2005 at 09:31 AM.. Reason: Missed the $
  #5 (permalink)  
Old 08-10-2005
MAKY MAKY is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 3
Sorry, but I still do not receive any result.
Did you try it ay your system and get the result ?
Thanks again
MAKY
  #6 (permalink)  
Old 08-10-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
#! /bin/sh

for file in `find /tmp/ -name '*.*'`
do
PATH=${file%/*}
FILE_OLD=${file#$PATH/}
FILE_NEW=${FILE_OLD//z/d}
mv ${file} ${PATH}/${FILE_NEW}
done
Vino

Last edited by vino; 08-10-2005 at 10:52 AM.. Reason: input for mv was wrong
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 11:35 AM.


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