Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read and keep spaces

Status
Not open for further replies.

thepom02

Programmer
Dec 13, 2002
9
US
I have a script that sequentially read thru a file in a while do loop. However leading spaces from the records are removed by the read, is there anyway to keep these spaces.

example

while read -r line
do
PROCESS goes here
done < $PrintFile

If my line is " Here is some text", $line only shows "Here is some text".

Thanks
Paul
 
You would have to set IFS to a null character before the read, e.g...
[tt](
IFS="\000"
while read -r line
do
:
done < $PrintFile
)[/tt]
 
You should have to set IFS to a null character just before the read" so as to not interfere with the other commands in the loop.
Code:
  while [COLOR=red]IFS="\000"[/color] read -r line
  do 
    :
  done < $PrintFile

This way the IFS is set to null only during the read.

--------------------

Denis
 
Thanks for both replies, that fixed my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top