pacman pacman - 6 months ago 36
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

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".

Comments