pacman pacman - 1 year ago 146
Linux Question

Using cut with unprintable delimiters

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.

Answer Source

If you're using Bash,

cut -d $'\001' ...

works (see Bash Reference Manual # 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".