On 2007-12-07, sancho1980 wrote:
>
> i have a script that reads lines from a file in this manner:
>
> cat infile | while read line

   You don't need cat.

> 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!

while IFS= read -r line
do
  printf "%s\n" "$line"
done < infile

-- 
   Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
   ===================================================================
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
.


Reply via email to