how to remove leading whitespace from filenames/folders snow?

Posted by timoto on Super User See other posts from Super User or by timoto
Published on 2012-03-26T23:51:07Z Indexed on 2012/03/27 5:32 UTC
Read the original article Hit count: 492

how do I remove leading whitespace from filenames/folders in OSX snow ?

As provided below by Lri I was able to remove trailing whitespace using this

#!/bin/bash

IFS=$'\n'
for d in {1..9}; do
    find ~/Desktop -name '* ' -depth $d | while read f; do
        mv "$f" "$(sed 's/ *$//' <<< "$f")"
    done
done

Now I'm trying to remove leading whitespace with this

#!/bin/bash

IFS=$'\n'
for d in {1..9}; do
    find ~/Desktop -name '* ' -depth $d | while read f; do
        mv "$f" "$(sed 's/^ *//;s/ *$//' <<< "$f")"
    done
done

but it doesn't work.

What am I doing wrong ?

© Super User or respective owner

Related posts about osx-snow-leopard

Related posts about removal