Operating System - HP-UX
1822494 Members
2417 Online
109642 Solutions
New Discussion юеВ

Embed ASCII Characters in text file

 
Bill Fisher
Occasional Contributor

Embed ASCII Characters in text file

Was curious if anyone could give me the proper way to embed an ESC in a text file. What I need is to send an ESC followed by the following text. TEST1ON. this will be sent out the serial port.

Thanks for looking
5 REPLIES 5
Carlos Fernandez Riera
Honored Contributor

Re: Embed ASCII Characters in text file

1- command way
echo "\033"TEST01


2-
file way
vi TEST_FILE
i
^V[esc key]TEST01
[ESC key]:w!

cat TEST_FILE
unsupported
Chris Vail
Honored Contributor

Re: Embed ASCII Characters in text file

This one is easy: "echo \033>>$FILE". This puts the octal equivalent of the escape character (decimal 027) in your text file.


Chris
Bill Fisher
Occasional Contributor

Re: Embed ASCII Characters in text file

Thanks for the quick responses. I should have been more explicit in my question. This is part of a configuration file for the serial ports and the ESC will need to be a part of the config file. A small example follows.

NUMBER OF TERMINALS: 2
TERMINAL NAME: TTY A
TERMINAL DEVICE: /dev/tty0p0
TERMINAL iflag: ICRNL |IXOFF |IXON
(all the rest of the TERMINAL settings)
Open relay string: ESCTEST1OFF
Close relay string: ESCTEST1ON
(relay 2 - 8 the same)
The text after the colon gets sent out the appropriate serial port. I can edit the file using vi or any editor.
Carlos Fernandez Riera
Honored Contributor

Re: Embed ASCII Characters in text file

If i've understood rigth, you wish chage ESC by esc char in the file, so try the second way.

type CNTRL-V and then type ESC key. You will see a ^[ in your screen that is teh esc (0x1b , 033 octal) char
unsupported
A. Clay Stephenson
Acclaimed Contributor

Re: Embed ASCII Characters in text file

Using vi:

Position the cursor at the desired insertion point:

Press "i" to enter Insertion Mode.
Enter "Cntrl-V" - the next character will be quoted without any interpretation. You should see a "^" to indicate that the next character is to be escaped.
Press ESCAPE (or any other desired control char)
Press ESCAPE again to end the insert.
:w to save the file
:q to exit vi.

You can check you work (if you don't trust the vi display) using od -c myfile.
If it ain't broke, I can fix that.