korn shell read command truncate spacing

Sun microsystems A33-aa e420r server bas...
May 5, 2010 at 11:47:40
Specs: Sun OS, Not know
I have problem with Unix korn shell read command:
>cat myFile.log
This  is a      test with random     spacing
Pay     attension  to the    # of spacing between each      word

>cat "myFile.log" | while read line
>>do
>> echo ${line}
>>done

This is a test with random spacing
Pay attension to the # of spacing between each word
>

Note: I get only single space instead of it original line? Is there a setup I need to do OR how to I fix it to get the exact line as the myFile.log show?


See More: korn shell read command truncate spacing

Report •

#1
May 5, 2010 at 11:55:43
To retain the white space, surround the variable with double quotes:

while read line
do
  echo "${line}"
done < myFile.log


Report •

#2
May 5, 2010 at 14:10:24
>cat myFile.log
This is a test with random spacing
Pay attension to the # of spacing between each word

>funcTest() {
>> curLine=$1
>> echo "++++${curLine}++++"
>>}

>cat "myFile.log" | while read line
>>do
>> funcTest "${line})
>>done

will give:
This is a test with random spacing
Pay attension to the # of spacing between each word


NOTE: It trims the leading and trailing space? How to prevent it?


Thanks


Report •

#3
May 5, 2010 at 16:25:00
Try placing double quotes around the "$1" argument:

funcTest() {
curLine="$1"
echo "${curLine}"
}


Report •
Related Solutions


Ask Question