[Tutor] stx, etx (\x02, \x03)

richard kappler richkappler at gmail.com
Tue Sep 22 14:37:56 CEST 2015


I have a file with several lines. I need to prepend each line with \x02 and
append each line with \x03 for reading into Splunk. I can get the \x02 at
the beginning of each line, no problem, but can't get the \x03 to go on the
end of the line. Instead it goes to the beginning of the next line.

I have tried:

#!/usr/bin/env python

with open('input/test.xml', 'r') as f1:
    with open('mod1.xml', 'a') as f2:
        for line in f1:
            s = ('\x02' + line + '\x03')
            f2.write(s)

as well as the same script but using .join, to no avail. What am I missing?

regards, Richard

-- 

All internal models of the world are approximate. ~ Sebastian Thrun


More information about the Tutor mailing list