modify a datastream on the fly

后端 未结 5 607
[愿得一人]
[愿得一人] 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:00

    Instead of the sed command, you can use this:

    perl -pe 's/(,\w+)/" " x length $1/ge'
    

    The e option on the substitution means that the right side of the s/// is evaluated as a Perl expression. In this case, the expression returns the correct number of spaces, based on the length of the captured match.

提交回复
热议问题