Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To get rid of special characters in filenames

Status
Not open for further replies.

irixfan

IS-IT--Management
May 14, 2002
57
FI
I need the syntax how to handle special characters '[]' in a csh (or another) script. In my directory several files have string '[1]' in their filenames and I would like to rename them all with a script to remove '[1]' from filenames. (like 'mv filename[1].jpg filename.jpg')
I guess the backslash \ is the solution but I can't get it work in a script.
 
Try something like this:
Code:
#!/bin/ksh
find . -name '*\[?\]*' -print |
 sed 's!\(.*\)\[1\]\(.*\)!mv \1[1]\2 \1\2!' | sh

Hope This Help
PH.
 
As per your example, if you have files with names like filename[1].jpg and you want to strip off the '[1]', then you can try the following script :

=========================
#!/bin/ksh
for i in `ls *\[*\].jpg`
do
mv $i `echo ${i%%\[*\]*}.jpg`
done
==========================

Hope this helps ya !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top