Skip to content
Home » Shell Script » How vi Editor Add Control Character

How vi Editor Add Control Character

Control Character

In some cases, developers may use a control character to delimit the data for every field in a flat file. For example, we can use ^A to delimit fields in vi editor.

Delimiter

[oracle@test tmp]$ vi testfile
some^Athing^Ais^Agood!

Let's see its content.

[oracle@test tmp]$ cat testfile
somethingisgood!

As you can see, the control character ^A is invisible to the users. How did we do that?

Solution

Let's see some usually used control characters.

Control A (Ctrl-A)

To simulate a Ctrl-A (^A) character in vi editor, you should press and hold Ctrl key then stroke v then a keys subsequently.

Control C (Ctrl-C)

In the same way, to type a Ctrl-C (^C) character, you should press and hold Ctrl key then stroke v then c keys subsequently.

In other words, we use "Ctrl + v", the combination keys to simulate typing a Ctrl key. This trick does work in both bash and ksh shell.

Control M (Ctrl-M)

To remove ^M (carriage return) from text in vi editor, we use the similar way to do it.

Leave a Reply

Your email address will not be published. Required fields are marked *