Ultimate Grocery List
October 11, 2012 – 1:31 am | No Comment

I was in the process of making a grocery list for me that was customized just for me. I opened up Excel and Word and started working on a template. Every grocery list should definitely …

Read the full story »
Food

Recipes, tools, techniques, and quick tips to help you work a kitchen like a pro.

Leadership

Leadership tools and techniques that I find interesting and useful (mainly the ones that work).

Music

Instrument and accessory reviews, tips, scales, practice sheets, and music.

Projects

Everyday project management tools to help my life run smooth and my personal projects.

Technology

Cool tech stuff that I find out there and things I find will help you go through your day.

Home » Technology, Tools

Removing Spaces Linux/Mac

Written by on August 14, 2009 – Follow me on Twitter No Comment | Print

bash

I had a bunch of files I needed to upload to a web server.  The filenames contained spaces and we know some web browsers don’t like spaces.  There was this script I found on the web.  It worked out really well.

#!/bin/bash

ls > /tmp/list
# we have to make the list file in a separate
# directory so that it doesn’t get included
# in the list of the current directory!
mv /tmp/list ./list
cat list | tr ‘ ‘ ‘_’ > listnew
# this turns spaces into underscores
FILE_COUNT=$(wc -l list | awk ‘{print $1}’)
LOOP=1
while [ "$LOOP" -le "$FILE_COUNT" ]
do
AWKFEED=”FNR==”$LOOP
# the command to feed awk
# output will be ‘FNR==1′, ‘FNR==2′, ..
OLDFILE=$(awk $AWKFEED list)
NEWFILE=$(awk $AWKFEED listnew)
mv “$OLDFILE” “$NEWFILE”
# keep the quotes to make the shell read file
# names with spaces as one file
LOOP=$(($LOOP+1))
done

rm list
rm listnew

exit 0

To get this to work, create a file in the same directory. Change the mode to make sure the file is executable.

References:
http://www.dba-oracle.com/t_fix_linux_data_file_names_special_characters.htm

Comments Welcome

All comments are welcome. I recently added reCAPTCHA to the verification process of comments because I was getting over 200 spam comments per day sorry to make the process a little harder but from the security perspective it makes sense to have. Thanks.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.