[ILUG] sed question

Ciaran Mac Lochlainn ciaran17 at eircom.net
Mon Aug 9 14:04:54 IST 2004


First of all, I'm not sure if sed is even the right tool for this job, 
but here goes-

I need to send a stream of output from a .net app on a windows box (or 
boxen) to a serial port on a Linux machine.  Each line has to contain a 
preamble which includes unprintable characters.  The .net app writes 
these in Unicode (e.g. \340 is written as \303\240) which the hardware 
device on the serial port can't interpret.

I thought of using a sed script on the Linux box to add the preambles 
instead, but I don't know how to get it to echo unprintable characters.  
I can get it to add text so long as it's in 7 bits.

The file trace2 contains data in the format "#003       Quantity set to 2".

cat trace2 | sed 's/^#/test#/'   gives me the output:
test#003       Quantity set to 2

cat trace2 | sed 's/^#/\027a\340\300\004\340\300\005\340\300\002#/'  
gives me:
027a340300004340300005340300002#003       Quantity set to 2

What I want is the first character to be a ^W  ...etc.

I tried dropping the single quotes in case they were forcing sed to 
interpret the replacement string literally, but this didn't help.

Any suggestions?



More information about the ILUG mailing list