Re: Read command and trailing spaces
From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 10/09/03
- Next message: Stephane CHAZELAS: "Re: 'if' conditional test"
- Previous message: Andreas Kahari: "Re: 'if' conditional test"
- In reply to: Diego Balgera: "Read command and trailing spaces"
- Next in thread: William Park: "Re: Read command and trailing spaces"
- Reply: William Park: "Re: Read command and trailing spaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Oct 2003 10:49:16 GMT
On Thu, 09 Oct 2003 at 09:43 GMT, Diego Balgera wrote:
> Hi,
> I have a script that reads a whole text file as follows:
>
> while read ROW
> do
> (processing ROW)
> done
>
> The ROW is a fixed-length row of 913 characters. Usually it works ok but
> when the row ends with spaces, the ROW doesn't contain them. In other words,
> the read command cuts the trailing spaces (since "read" interprest spaces as
> variable separators).
> Could you please suggest a method to avoid this, so that ROW will always
> contain all the 913 characters, trailing spaces included?
Set the field separator, $IFS, to an empty string, so that read
doesn't use spaces as a separator, e.g.:
while IFS= read ROW
do
## process $ROW
done
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: Stephane CHAZELAS: "Re: 'if' conditional test"
- Previous message: Andreas Kahari: "Re: 'if' conditional test"
- In reply to: Diego Balgera: "Read command and trailing spaces"
- Next in thread: William Park: "Re: Read command and trailing spaces"
- Reply: William Park: "Re: Read command and trailing spaces"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|