Re: Read command and trailing spaces

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 10/09/03


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


Relevant Pages

  • Read command and trailing spaces
    ... (processing ROW) ... The ROW is a fixed-length row of 913 characters. ... the read command cuts the trailing spaces (since "read" interprest spaces as ...
    (comp.unix.shell)
  • Re: Visual basic 6 ado error 3662 "operation was canceled"
    ... created as nchar with a fixed length of 50 characters so seem to be padded ... characters which SQL server thought was going to take the field over its max ... > tabs and or trailing spaces from somewhere) then i can change it no problem. ... > unless you replace the whole field by selecting and overtyping it. ...
    (microsoft.public.data.ado)
  • Re: Inspect...
    ... > encounter two spaces (and some other characters). ... > between Mike and Daniel) but 'MIKE DANIEL ' is not. ... > trailing spaces. ... NAME.ZIP from my website below under "COBOL Source Files." ...
    (comp.lang.cobol)
  • Re: building a text string with null fields
    ... Trailing spaces ... characters. ... have the ten positions added to the string. ... would some kind of format command with '@@@@@@@@@@' work to make sure the ...
    (microsoft.public.access.modulesdaovba)
  • RE: Combo Box Question with Spaces
    ... This will include leading and embedded spaces, ... If you need to have trailing spaces displayed, ... "Markus" wrote: ... > always the same so where there is no characters it must give me a blank space ...
    (microsoft.public.access.forms)