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?


Two ways:

Press Ctrl-v + Tab

cut -f2 -d'   ' infile

or write it like this:

cut -f2 -d$'\t' infile

Tab is the default.

See the cut man page.

-d delim
         Use delim as the field delimiter character instead of the tab

So you should just write

cut -f 2
  • 2
    Oops didn't notice that line. – Muhammad Hasan Khan Mar 30 '12 at 15:54
  • 4
    But it is probably always safer to mention such flags explicitly, for both readability and portability. I can imagine some people designing a cut for Windows would not follow the complete standard. – Willem Van Onsem Apr 19 '15 at 12:32
  • 1
    This should be accepted answer: simplest code, simplest explanation. ya nailed it: youtube.com/watch?v=dpNTHl7y45Y – neuronet Jun 16 '16 at 21:28
  • 4
    This answer has changed my life – matheeeny Apr 28 '17 at 13:00

awk '{ print $2; }' inputfile

  • 8
    That will fail if $1 contains spaces. Specify the field separator. – manatwork Mar 30 '12 at 11:32
  • If you wish to preserve other whitespace than \t, then it will fail. Otherwise not. – Iľja Mar 30 '12 at 12:07
  • 9
    @ipip The question specifically mentions tabs instead of spaces. – Burhan Ali Mar 30 '12 at 13:04

More generically, without requiring any invisible characters: Use tr to convert the delimiters to a format that can be specified more easily to cut.

$ echo -e "a\tb\tc" |tr '\t' ' ' |cut -d' ' -f2

tr is a simple, but powerful, character matching and replacement tool.

protected by Community Oct 23 '17 at 22:06

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.