|> Hi
|> this works:
|> $for i in 'a b c' 'd e f'
|> >do
|> > echo $i
|> >done
|> a b c
|> d e f
|>
|> This does not:
|> $cat file
|> a b c
|> d e f
|> $for i in `cat file`
|> >do
|> > echo $i
|> >done
|> a
|> b
|> c
|> d
|> e
|> f
|>
|> How do I give the for the strings "a b c" "d e f" ? I tried adding " with awk
|> and tricks with eval, but it does not work. Is there a solution?
|> I would prefer not to reread the entire file for each line ...
What you need to do is to reset the Internal Field Separator (IFS) to 'newline'.
The for loop extracts each field. In your case, the field separator is
probably set to space, tab, and newline; therefore, the spaces in each
line are acting as a field separator and the 'for' loop is seeing each
of these characters as a separate field in the line separated by spaces.
You want it reset the IFS to newline only. Following are a couple of
examples.
Try this...
$ IFS=" # Just hit the enter key here#
Quote:> "
$ for i in `cat file`; do
Quote:> echo $i
> done
a b c
d e f
$
If you want to save the old IFS value prior to changing it, try
$ OLD_IFS=${IFS}
$ IFS="
Quote:> "
$ for i in `cat file`; do
Quote:> echo $i
> done
a b c
d e f
$ IFS=${OLD_IFS}
--
+==============================+===========================================
==+
| David W. Pledger | S T R A T E G I C D A T A S Y S T E M S |
| Custom Database Applications | Phone (513)748-2460, (800)253-5624 ext 2940 |