Operating System - HP-UX
1833535 Members
2952 Online
110061 Solutions
New Discussion

Re: Getting rid of empty file-names?

 
SOLVED
Go to solution
Petter Selin
Occasional Advisor

Getting rid of empty file-names?

Hi.

I`ve made a script that automatically creates files depending on anothers files substance. (or...i didnt made it...i had help from this forum...=))..

The question is...Some of the files that are created get blank file names (one space and 2 spaces)....How can i get rid of them?
cd /Symbols/
(one blank Space) (2 spaces) benelli triumph


I have tried following...

if [ "`cat $file`" == *[a-z,0-9] ]
then echo `cat $comp` >> Symbols/`cat $file`
else :
fi

This will create on of the files "benelli"...but triumph, and the 2 with blank filenames will dissapear...But if i invert it..( != )...the other files will be shown....

why doesnt "triumph" pass when "benelli" does it?

b.r
Petter
3 REPLIES 3
Robin Wakefield
Honored Contributor
Solution

Re: Getting rid of empty file-names?

Hi Petter,

You can either enclose the filename in quotes or run in interactive mode:

ls -lo
total 6
-rw-r----- 1 root 4 Sep 25 08:57
-rw-r----- 1 root 6 Sep 25 08:55 abc
-rw-r----- 1 root 7 Sep 25 08:55 def

rm ' '
rm ' abc'

or

rm -i *

When you create the files within your script, you should check for and remove the spaces.

Rgds, Robin
Ralph Grothe
Honored Contributor

Re: Getting rid of empty file-names?

simply escape the spaces

e.g.

$ rm filename\ with\ spaces
Madness, thy name is system administration
Petter Selin
Occasional Advisor

Re: Getting rid of empty file-names?

Hehe...It sure did it...Why did I have to try to make it more complicate than it really was?....thnxs m8..

"Every problem is easy as long as you know the answer"