Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to use cut command to break input into fields and get the second field. cut -f2 -d' ' <--- How can I tell it to use tab instead of space

share|improve this question

3 Answers 3

up vote 36 down vote accepted

Two ways:

Press Ctrl-v + Tab

cut -f2 -d'   ' infile

or write it like this:

cut -f2 -d$'\t' infile
share|improve this answer
2  
$'' — bash'ism, AFAIR –  poige Mar 30 '12 at 11:45

Tab is the default.

See the cut man page.

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

So you should just write

cut -f 2
share|improve this answer
    
Oops didn't notice that line. –  Hasan Khan Mar 30 '12 at 15:54

awk '{ print $2; }' inputfile

share|improve this answer
3  
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. –  ipip Mar 30 '12 at 12:07
3  
@ipip The question specifically mentions tabs instead of spaces. –  Burhan Ali Mar 30 '12 at 13:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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