3

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 ?

2 Answers 2

8

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

4 Comments

it will not work always, because i use some key-binding in vim.
and when in shell, it will not work always neither, because of some key-binding in my term.
Well, since everything is bindable in vim, I can only give you standard bindings. Also... why would you imap <C-V>?
Well, that's a way to solve! But exactly i'am an emacser, I use vim not very often.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.