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.
cut uses tab as a default field delimiter but can also work with other delimiter by using -d option. Note: Space is not considered as delimiter in UNIX.
Use 'tr' to change each of the delimiters to a common delimiter. That way 'cut' only has to deal with one delimiter. Use multiple 'cut's, each with a different delimiter, in a pipeline to get at only the data you want. This can be hard if the delimiters are mixed in the data.
The tab character is the default delimiter of cut, so by default, it considers a field to be anything delimited by a tab. Remember that the "space" between each word is actually a single tab character, so both lines of output are displaying ten characters: eight alphanumeric characters and two tab characters.
The following command line options are used by the cut command to make it more specific: -b, --bytes=LIST: It is used to cut a specific section by bytes. -c, --characters=LIST: It is used to select the specified characters. -d, --delimiter=DELIM: It is used to cut a specific section by a delimiter.
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".
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With