How to type ^A in unix shell script/VI

2019-06-25 08:47发布

问题:

I am new to unix and writing script to extract data in delimited file format.

want to use ^A as delimiter , can you please suggest how to type/insert it

回答1:

Type Ctrl + V, then Ctrl + A.

According to your system configuration, you may need to type other key sequence. Check the output of stty -a, especially lnext:

$ stty -a | grep lnext
lnext = ^V; flush = ^O; min = 1; time = 0;
^^^^^^^^^^


回答2:

In vi, you can generally type CTRL-V in insert mode, followed by another control character.

That's also true in the bash shell if you're in vi editing mode (entered with CTRL-K).

In emacs editing mode (usually entered by using the up arrow key), you would use CTRL-Q as a prefix command, before entering the character you want.

For example, here's my shell session showing the use of CTRL-VCTRL-A (which shows up as ^A):

pax> echo -n "^A" | od -b
0000000 001
0000001

You can see that the octal dump of the single character is indeed CTRL-A, or 001.



回答3:

I think the answer is '\001', but I'm not a very experienced shell scripter.

Here is a link that helped:

http://docstore.mik.ua/orelly/unix/upt/ch45_35.htm



回答4:

You can type :h digraph-table to see the digraph-table text that describes the character. Then you can input Ctrl + K and the digraph line consponsed to your character.



标签: shell unix vi