OT: shell scripts (was: Help me understand this!)

Kenneth Brody kenbrody at bestweb.net
Wed Jul 21 11:43:05 PDT 2004


"Lerebours, Jose" wrote:
[...]
> So, the written file ends-up looking like so
> 
> 0123456789012345678901234567890
> FIELD1LN1  FIELD2LINE1
> FIELD1LN2  FIELD2LINE2
> FIELD1LN3  FIELD2LINE3
> 
> etc, etc, etc ...
> 
> I then use shell script to run a for/next loop
> 
> for X in `cat filename`
> do
> 
> echo "$X"
> 
> done
> 
> The displayed text is as follows
> 
> FIELD1LN1
> FIELD1LINE1
> FIELD1LN2
> FIELD2LINE2
> FIELD1LN3
> FIELD2LINE3
> 
> I am expecting to retain both fields side by side
> in $X.  If I vi the file it looks fine.  If I cat
> the file it looks fine ...
[...]

It's your use of `cat filename` in the for loop.  This will cause each
"word" in the file (not each _line_) to be enumerated.

Try this to help you see why:

    echo `cat filename`

Instead, use:

    while read X
    do
      ...
    done <filename

-- 
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody        | www.hvcomputer.com |                             |
| kenbrody at spamcop.net | www.fptech.com     | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+



More information about the Filepro-list mailing list