How to remove leading whitespace from file and folder names?
- by timoto
How to remove leading whitespace from file and folder names? (I'm running OS X 10.6 Snow Leopard.)
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?