Operating System - HP-UX
1834202 Members
2897 Online
110066 Solutions
New Discussion

read cmd truncating leading spaces

 
SOLVED
Go to solution
Jim Green_1
Occasional Advisor

read cmd truncating leading spaces

I'm trying to use the read command such as:
while read LINE
do
process stuff...
done < input.file

input.file looks something like:
line1 starting pos 3
line2 starting pos 3
line3 starting pos 3
etc...

When I examine the var "$LINE"
it looks like:
line1 starting pos 3
line2 starting pos 3
line3 starting pos 3

How can I get the read command to leave the leading spaces intact???
Also, the UNIX 'line' command was not a viable alternative.
Thanks,
jg
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: read cmd truncating leading spaces

Hi Jim:

You can reset the IFS (Inter-Field Seperator) to achieve this. For instance:

# OLDIFS=$IFS
# IFS=:
# while read LINE
> do
> echo "${X}"
> done < input.file
# IFS=$OLDIFS

Regards!

...JRF...
Michael Steele_2
Honored Contributor

Re: read cmd truncating leading spaces

Also try:
perl -pe 1 file

For one line at a time in Perl.
Support Fatherhood - Stop Family Law