Results 1 to 5 of 5

Thread: script

  1. #1


    Member Since
    Jun 14, 2006
    Posts
    140
    script
    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!

  2. #2

    cazabam's Avatar
    Member Since
    Jun 06, 2006
    Posts
    1,153
    Specs:
    MacBook 2.0GHz White, 512MB RAM, 60GB HDD
    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).

  3. #3


    Member Since
    Jun 14, 2006
    Posts
    140
    awesome.. thanks!

    what do I save the file extension as?

  4. #4

    cazabam's Avatar
    Member Since
    Jun 06, 2006
    Posts
    1,153
    Specs:
    MacBook 2.0GHz White, 512MB RAM, 60GB HDD
    .sh should do, although it's just for your benefit really. To run it from a script, use `sh {scriptname}`

  5. #5


    Member Since
    Jun 14, 2006
    Posts
    140
    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/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to script
    By Ryanhh123 in forum Web Design and Hosting
    Replies: 4
    Last Post: 11-24-2011, 06:46 PM
  2. Terminal -- shell script -- script will only read two lines of a file
    By Straitsfan in forum OS X - Apps and Games
    Replies: 0
    Last Post: 01-30-2011, 10:04 PM
  3. Script help
    By skase in forum OS X - Operating System
    Replies: 1
    Last Post: 10-18-2007, 04:11 AM
  4. looking for a script
    By idea3 in forum Web Design and Hosting
    Replies: 1
    Last Post: 08-18-2007, 06:06 PM
  5. Can I Script?
    By PDinh73 in forum OS X - Operating System
    Replies: 4
    Last Post: 08-08-2005, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •