363

Here is an example of using cut to break input into fields using a space delimiter, and obtaining the second field:

cut -f2 -d' '

How can the delimiter be defined as a tab, instead of a space?

ilkkachu
  • 138,973
Muhammad Hasan Khan
  • 3,733
  • 2
  • 15
  • 6

6 Answers6

511

Two ways:

Press Ctrl+V and then Tab to use "verbatim" quoted insert.

cut -f2 -d'   ' infile

or write it like this to use ANSI-C quoting:

cut -f2 -d$'\t' infile

The $'...' form of quotes isn't part of the POSIX shell language (not yet), but works at least in ksh, mksh, zsh and Busybox in addition to Bash.

ilkkachu
  • 138,973
Birei
  • 8,124
  • This should not be the accepted answer, see: https://unix.stackexchange.com/a/35387/391735 – JBoy Oct 27 '22 at 12:45