[lug] scripting with spaces in strings

Chip Atkinson chip at pupman.com
Wed Oct 13 16:41:15 MDT 2004


Greetings,

I have a file containing file names with spaces in them and want to loop
through it and have the possibly space containing file names treated as a
single item.

For example, I have a file containing
a b c d
e f g
hijk
l m n o

I've tried 
for i in $(grep [a-z] junkdat | sed -e 's/ /\\ /'); do
> echo $i
> done
 
and 

for i in $(echo '"'$(grep [a-z] junkdat | sed -e 's/
/\\ /')'"'); do
> echo $i
> done

I basically get the following output:

"a\
b
c
d
e\
f
g
hijk
l\
m
n
o"


What I'd like would be

a\ b\ c\ d
e\ f\ g
hijk
l\ m\ n\ o

Any suggestions/thoughts?  I'm puzzled.

Thanks!

Chip




More information about the LUG mailing list