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
In the Perl, with added check that the string starts with NAM
and replacing really the ,FIRSTNAME
:
nc -kl 1100 | \
perl -pe '/^STX NAM / && do { s/(,FIRSTNAME)/" " x length("$1")/ge }' | \
nc <...>
In Perl s///e
as expected does substitution, but evaluates the replacement string as an e
xpression. Operator x
makes a new string, duplicating string on the left number of times given on the right. Non-matching strings are obviously not modified.