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: Chris F.A. Johnson
Subject: Re: reading whitespaces and beginning and end of line
Date: Fri, 7 Dec 2007 17:10:37 -0500
User-agent: slrn/0.9.8.1 (Linux)

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

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