An amazing premise: you are extracting an IP variable from a TXT file - if the file is Windows or is encoded in Windows style, the lines end with \r\n. You remove the new line, but what if there is one in it \rthat makes you return to the beginning of the line?
Quick dirty fix without question: use echo -n, it suppresses a new line at the end of the echo text.
echo -n $IP; echo -n of; echo -n $IPLINES
, , . $IP.
: OSX, . OSX \r - .