944,221 Members | Top Members by Rank

Ad:
Jun 20th, 2007
0

read line is stripping leading spaces

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeromefong is offline Offline
1 posts
since Jun 2007
Jun 20th, 2007
0

Re: read line is stripping leading spaces

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rusman is offline Offline
17 posts
since Feb 2006
Jun 20th, 2007
0

Re: read line is stripping leading spaces

Click to Expand / Collapse  Quote originally posted by jeromefong ...
[...]
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. $
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
radoulov is offline Offline
54 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: grep '^[a-zA-Z]'
Next Thread in Shell Scripting Forum Timeline: awk output separators?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC