How to extract the first column from a tsv file?

Try this (better rely on a real csv parser...):

csvcut -c 1 -f $'\t' file

Check csvkit

Output :

Harry_Potter
Lord_of_the_rings
Shameless

Note :

As @RomanPerekhrest said, you should fix your broken sample input (we saw spaces where tabs are expected...)


You can use cut which is available on all Unix and Linux systems:

cut -f1 inputs.tsv

You don't need to specify the -d option because tab is the default delimiter. From man cut:

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

As Benjamin has rightly stated, your awk command is indeed correct. Shell passes literal \t as the argument and awk does interpret it as a tab, while other commands like cut may not.

Not sure why you are getting just the first character as the output.


You may want to take a look at this post:

  • Difference between single and double quotes in Bash

Tags:

Awk

Sed

Cut