简体   繁体   中英

how to use non-printable char as field separator of sort command in bash?

The sort command has a parameter "-t" to declare the fields separator instead of the default blank. For example:

sort -t 'a' file

what if I want to use a non-printable char as the spearator, like the fifth char in ASCII table ?

There is a special quoting in bash, that can be used for this purpose. Try the following command and look for $'...' in the bash manual:

sort -t $'\05' file

You can enter a non-printable character in bash (and also in vim) by using ctrl-V and then the non-printable control code. Thus, for character 0x04, Ctrl-V Ctrl-D inserts ^D , which is a representation of the character 0x04.

Press:

sort -t '<ctrl-V><ctrl-D>' file

and this will be displayed:

sort -t '^D' file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM