1840213 Members
3332 Online
110162 Solutions
New Discussion

White Space

 
SOLVED
Go to solution
Steve Massey_1
Frequent Advisor

White Space

Hi

What is the best way to remove white space from a file name

Steve
7 REPLIES 7
CHRIS_ANORUO
Honored Contributor

Re: White Space

Move the file. (mv tod*ay newname)
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Steve Massey_1
Frequent Advisor

Re: White Space

Thanks Chris

But I should have given more detail

I am writing a script that takes a filename - with non alpha numeric chars - and I want to remove them

Steve
Patrick Wessel
Honored Contributor

Re: White Space

mv "name with black" namewithoutblack
There is no good troubleshooting with bad data
Brian M. Fisher
Honored Contributor
Solution

Re: White Space

The tr (translate characters) command may give you the options you are after. It can be used to remove "white space".

man tr

Brian
<*(((>< er
Perception IS Reality
Patrick Wessel
Honored Contributor

Re: White Space

well, I guess I posted my first answer to fast.

this line should do the trick:

string_without_space=`echo $string_with_blank | sed -e 's/ //g'`
There is no good troubleshooting with bad data
Alan Riggs
Honored Contributor

Re: White Space

To generalize the sed command for any particular set of non-standard characters use:

good_name=`echo bad_name|sed 's/[]//g'
mv $bad_name $good_name
Duane Gorder
Advisor

Re: White Space

I like Alan Riggs' answer, but remember that some of the special characters that you might want to list will have to be "escaped" with th \ character.
Live each season as it passes; breathe the air,