New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Apps and Games Discussion of applications and games available for Mac OS X.

script


Post Reply New Thread Subscribe

 
Thread Tools
unplugged

 
Member Since: Jun 14, 2006
Posts: 140
unplugged will become famous soon enough

unplugged is offline
Not sure if this is the right forum, but can someone write me a script that will strip all 2nd spaces in a file name?

Example. If a file name is: Junk Mail.txt it will make it Junk Mail.txt (gets rid of the extra space. Everytime I transfer files to my linux box that have more than one consecutive space, it doesn't seem to open, transfer back, or anything. I'm not sure if there is an option in linux to fix this (running SuSe 10.1). But I would like to have a script to be able to do this to all files in a single directory.

Thanks!
QUOTE Thanks
cazabam

 
cazabam's Avatar
 
Member Since: Jun 06, 2006
Posts: 1,153
cazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of light
Mac Specs: MacBook 2.0GHz White, 512MB RAM, 60GB HDD

cazabam is offline
There's no reason you can't have multiple consecutive spaces in filenames in linux. You just have to remember to put quotes round the filename or escape each space individually.

However, to do what you want, try this (it should work under Linux, and quite possibly under Mac OS X too, as long as you are using bash)

Code:
for f in *
  do
  n=${f//  */ /}  # <-- note that this is f//{space}{space}*/{space}/
  mv "$f" "$n"
done
Run this in the directory containing the files and it will do the magic. The 'for f in *' line can be changed to match just the files (e.g. for f in *.txt).
QUOTE Thanks
unplugged

 
Member Since: Jun 14, 2006
Posts: 140
unplugged will become famous soon enough

unplugged is offline
awesome.. thanks!

what do I save the file extension as?
QUOTE Thanks
cazabam

 
cazabam's Avatar
 
Member Since: Jun 06, 2006
Posts: 1,153
cazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of lightcazabam is a glorious beacon of light
Mac Specs: MacBook 2.0GHz White, 512MB RAM, 60GB HDD

cazabam is offline
.sh should do, although it's just for your benefit really. To run it from a script, use `sh {scriptname}`
QUOTE Thanks
unplugged

 
Member Since: Jun 14, 2006
Posts: 140
unplugged will become famous soon enough

unplugged is offline
alright, thanks! I need to learn how to write more shell commands.. would make organizing my files a lot easier :-)

MacBook Pro - 2.33Ghz, 2GB, SuperDrive, OS X 10.4.10
http://web.mac.com/mhadjar/
QUOTE Thanks

Post Reply New Thread Subscribe


« Looking for an FTP program. | External drive backup software? »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Script Wrapper?? meskue OS X - Development and Darwin 1 06-24-2006 02:02 PM
Quick Apple Script Question ezhangin OS X - Development and Darwin 6 12-14-2005 09:30 PM
MacAddict Backup Script sevenhelmet OS X - Development and Darwin 7 09-18-2005 03:56 PM
Need some help on a unix script :-) starrin OS X - Operating System 0 12-01-2004 08:55 PM
Ooops - dragged a script to the Finder!! kjellquist OS X - Operating System 1 03-15-2004 06:46 PM

All times are GMT -4. The time now is 12:48 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?