read line is stripping leading spaces

Reply

Join Date: Jun 2007
Posts: 1
Reputation: jeromefong is an unknown quantity at this point 
Solved Threads: 0
jeromefong jeromefong is offline Offline
Newbie Poster

read line is stripping leading spaces

 
0
  #1
Jun 20th, 2007
I'm writing a Bash script to read from an input file and write my changes out to an output file. I'm using read and for some reason, it is stripping the leading spaces off of each line. I didn't see any flags in read to turn the stripping off. I'm also runnig this in cygwin, but I don't think that should matter.

The code I am using is something like this.
while read curline;
do
echo "current line " $curline
if [ ! -z "$curline" ]; then
while read outline;
do
echo "$curline" >> $Output_Work
fi
done < $Input_Work

Am I doing something wrong here?

thanks,

Jerome
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 17
Reputation: rusman is an unknown quantity at this point 
Solved Threads: 0
rusman rusman is offline Offline
Newbie Poster

Re: read line is stripping leading spaces

 
0
  #2
Jun 20th, 2007
In my very limited scripting experience, read will ignore spaces. You might be able to change that but I don't know how.

I have a read question, too, in another thread I just posted.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 54
Reputation: radoulov is an unknown quantity at this point 
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: read line is stripping leading spaces

 
0
  #3
Jun 20th, 2007
Originally Posted by jeromefong View Post
[...]
I'm using read and for some reason, it is stripping the leading spaces off of each line.
[...]
Consider this:

Shell Scripting Syntax (Toggle Plain Text)
  1. $ cat infile
  2. a
  3. a
  4. a
  5. $ while read;do
  6. while> echo "$REPLY"
  7. while> done<infile
  8. a
  9. a
  10. a
  11. $ while IFS= read;do
  12. echo "$REPLY"
  13. done<infile
  14. a
  15. a
  16. a
  17. $
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC