Originally Posted by Jykke
So all in all I think it is allergic to spaces in my file1 and treats a line as three separate strings. So perhaps it is in the layout of for - loop and using cat.
Yes. That's exactly the reason: the loop is iterated over the three fields separated by space. The shell uses the blank space (together with TAB and newline) to separate fields (check the IFS built-in variable). You can alter the value of IFS to protect the space from being considered the field separator or - better - you can do:
while read line
something with "$line"
done < $1
In this case the read
statement takes care of assigning the whole line to the loop variable (despite the presence of blank spaces or any other special symbol). Just put the reference to $line inside double quotes when you use it.