views:

113

answers:

3

Is it possible to use cut and have unprintable characters be the delimiter? For example I'd like to have the "^A" characters (also represented as \001) be the delimiter.

+2  A: 

Yes, it's perfectly possible.

If typing in a shell, press ^V and then ^A to insert the ^A verbatim in the current line rather than have it treated as the normal 'go to start of line' command:

% cat -v foo
abc^Adef^Aghi
% cut -d^A -f2 foo
def
Alnitak
A: 

CTRL-V CTRL-A ?

+3  A: 

If you're using Bash,

cut -d $'\001' ...

works (see Bash Reference Manual # 3.1.2.4 ANSI-C Quoting).

Other (more portable) options,

cut -d `echo -e '\001'` ...

FS=`echo -e '\001'`
cut -d $FS ...

or inserting the control character directly using ^V as mentioned by Alnitak and etlerant -- on the shell command line, and in editors such as vi, this means "don't treat the next thing I type specially".

ephemient