0

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

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by radoulov
0

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.

0

[...]
I'm using read and for some reason, it is stripping the leading spaces off of each line.
[...]

Consider this:

$ cat infile
a
 a
        a
$ while read;do
while> echo "$REPLY"
while> done<infile
a
a
a
$ while IFS= read;do
echo "$REPLY"
done<infile
a
 a
        a
$
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.