I have a file containing some data and I want to use only the first column as a stdin for my script, but I'm having trouble extracting it. I tried using this
awk -F"\t" '{print $1}' inputs.tsv
but it only shows the first letter of the first column. I tried some other things but it either shows the entire file or just the first letter of the first column.
My file looks something like this:
Harry_Potter 1
Lord_of_the_rings 10
Shameless 23
....
awk to print the first column. The first column of any file can be printed by using $1 variable in awk. But if the value of the first column contains multiple words then only the first word of the first column prints. By using a specific delimiter, the first column can be printed properly.
Use grep/awk to remove part of column.
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:
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