I need to hijack and modify a datastream. The stream consists of fixed-width commands. Each command is a new line, and the documentation says that each command starts and ends
Here's a sed
version:
sed 'h;s/[^,]*,\([^ ]*\) ETX/\1/;s/./ /g;x;s/,.*/,/;G;s/\n//;s/$/ ETX/'
I'd be willing to bet that not only is the command fixed width, but that the fields are also fixed width. If that's the case then something like this would probably work:
sed 's/\(.\{22\}\).\{9\}\(.\{4\}\)/\1 \2/'
or
sed -r 's/(.{22}).{9}(.{4})/\1 \2/'
or
sed -r 's/STX (.{18}).{9} ETX/STX \1 ETX/'