I have a question about how to read my file correctly in UNIX, I have the file given (attached as image) and this file has tabs between the variables, as you can see Blood is a variable and Whole Blood is another one. However, when I write in the terminal gawk '{print $7}'file.txt | head the result is the other attached image that you can see. I mean, the system is counting like this:

GTEX-1117F-0003-SM-58Q7G ($1)
B1 ($2)
Blood ($3)
Blood ($4)
Whole ($5)
0013756 ($6)
1188 ($7)

At this position should be Whole Blood and not 1188, so I need to know how could I solve this problem. I need something like this:

Thanks in advance

File given enter image description here file needed

  • 2
    Welcome to Unix & Linux! Please don't post images of text. Instead, copy/paste the text into your question and use the formatting tools to format it as code. The images are unfortunately completely useless for us since we cannot take them and test any solutions we come up with.
    – terdon
    Mar 24 at 18:01
  • 1
    Are you just looking for gawk -F'\t' '{print $7}' file.txt?
    – terdon
    Mar 24 at 18:08
  • Thank you for answering, and yes the command worked. Mar 24 at 19:27

The variable Input Field Separator defaults to all kinds of spaces. You want it to explicitly set it to a tab. The man page of awk says:

  -F sepstring
             Define the input field separator. This option shall be
             equivalent to:

                 -v FS=sepstring

And further down:

  FS        Input field  separator  regular expression; a <space> by default.

So, to set the FS to a tab:

$ awk -F'\t' '{print $7}' file.txt
  • thank your for your response. Now, I understood why I needed -F and ' \t'. I'm new in this, so I didn't know what to do. Mar 24 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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