bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading whitespaces and beginning and end of line


From: Dave Rutherford
Subject: Re: reading whitespaces and beginning and end of line
Date: Fri, 7 Dec 2007 11:25:47 -0500

On Dec 7, 2007 5:49 AM, sancho1980 <martin.knappe@gmail.com> wrote:
> i have a script that reads lines from a file in this manner:
>
> cat infile | while read line
> do
>     echo "$line" >> outfile
> done
>
> The problem I have occurs whenever there is a whitespace at the end of a
> line in the input file, because this whitespace get automatically truncated
> from "$line", and i dont want that..i want the whole line to go into
> outfile, no matter if the last characters are whitespace!

You do win the coveted "useless use of cat" award, but even
with that I can't reproduce your problem here.  What version
of bash are you using?

$ cat -t -E test1
this $
file  $
contains some   $
extra^I$
whitespace   $
$ while read; do echo "$REPLY" >> test2; done < test1
$ cat test1 | while read; do echo "$REPLY" >> test3; done
$ l test*
-rw-r----- 1 dave dave 51 Dec  7 11:19 test1
-rw-r----- 1 dave dave 51 Dec  7 11:19 test2
-rw-r----- 1 dave dave 51 Dec  7 11:19 test3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]