Bash: how to supress newlines?
- by gilgongo
I'm trying to extract fields from a pipe-delimited file and provide them as arguments to an external program in a loop. The file contains lines like this:
value1|value2
value3|value4
So I came up with:
while read line;
do echo -n "${line}" | awk -F '|' '{print $1}';
echo -n " something ";
echo -n "${line}" | awk -F '|' '{print $2}';
echo " somethingelse";
done < <(cat $FILE)
I want to see the following output:
value1 something value2 somethingelse
value3 something value4 somethingelse
But instead I'm getting:
value1
something value2
somethingelse
value3
something value4
somethingelse
Perhaps I shouldn't be using echo?