I have a server which sends data in a UDP Broadcast on port 10552. The data is 7 numbers separated by commas as so.
5.351204,0.001968,-0.000473,-0.999222,0.000451,0.001455,1.084310
I fetch this data with
socat -u udp-recv:10552,reuseaddr -
I want to change the format of this data, so I pipe it into sed. I don't care about the first number, so I remove it with
s/[^,]*,//;
I add spaces after the commas with
s/,/, /g
I then add an open parenthesis to the beginning of each line with
s/^/(/
Finally, I attempt to add a close parenthesis to the end of each line with
s/$/)/
The final command ends up being
socat -u udp-recv:10552,reuseaddr - | sed 's/[^,]*,//;s/,/, /g;s/^/(/;s/$/)/'
Everything works as expected, except the final close parenthesis ends up on the beginning of each line, so it looks like
)0.051727, -0.595779, -0.794678, 0.082047, 0.644327, -0.027242
Removing the last bit of the command for
socat -u udp-recv:10552,reuseaddr - | sed 's/[^,]*,//;s/,/, /g;s/^/(/;'
results in
(0.079330, -0.608597, -0.786194, 0.092438, 0.657444, -0.031528
I have tried replacing appending the end of the line with awk, tr, and also GNU sed, but everything seems to overflow the line or something.
I am on OS X 10.10.3 with the builtin Bash 3.2. Is there anything else I can try?