modify a datastream on the fly

后端 未结 5 540
[愿得一人]
[愿得一人] 2021-01-27 09:21

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

5条回答
  •  时光说笑
    2021-01-27 10:03

    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/'
    

提交回复
热议问题