Bash: how to supress newlines?
Posted
by gilgongo
on Stack Overflow
See other posts from Stack Overflow
or by gilgongo
Published on 2010-03-13T12:48:22Z
Indexed on
2010/03/13
12:55 UTC
Read the original article
Hit count: 259
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?
© Stack Overflow or respective owner