views:

115

answers:

0

Possible Duplicate:
modify a datastream on the fly

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 with an STX/ETX (start and end of text) pair.

The sending system is using serial, but is attacked to an iPocket device that communicates over IP to our PBX. From what I can tell it's just converting the serial to telnet, which should keep things pretty simple hopefully.

The string I need to look for starts with NAM. The structure is something like this:

STX NAM EXT# LASTNAME,FIRSTNAME ETX

I need to replace ,FIRSTNAME with whitespace so it doesn't change the length of the command.

I've been attempting the following, and while it passes the data end to end in both directions as required, and removes the needed data, it isn't maintaining the length of the command.

ipocket <-> nc -kl 1100 | sed 's/,[^,]*/ /g' | nc target_ip target_port <-> PBX

I'll be using a Linux box for this task. I'm reasonably certain that this could be done quite simply in Perl or Python but I haven't got a clue where to start. Any assistance would be greatly appreciated!