Help with selecting column with awk for a txt file generated by excel

I am new to scripting/programming, so I apologize for any novice questions.

I have a tab delimited text file that was saved from excel xls file.

I am trying to select only the third column using awk command. My command line is as below:

cat test.txt | awk '{print $3}'

However, above command line only generates the first row of the third column. How can I generate a tab delimited text file from excel spread sheet that has correct formatting, so that awk command will select the entire column and not just the first row of the column?

Thank you for all your help. I did try searching in this forum and google, but I could not find how to make the the txt file with correct format.

Thanks again.

Can you give some sample lines from the text file?

Hi Mobitron,

Here are some of my sample file (sorry for the long row):

157    160    161    163    167    181    216    247
PGP_AHY56    PGP_MOY83    PGP_JFY63    PGP_JCY63    PGP_SCY57    PGP_MHY59    PGP_JCY84    PGP_JRY66
COC076    COC072    COC084    COC079    COC094    COC105    COC134    COC144
Addicts    Addicts    Addicts    Addicts    Addicts    Addicts    Addicts    Addicts
F    F    M    F    M    M    M    M
49    22    42    42    48    46    21    40
-5.25    0.226190476    -0.785714286    3.952380952    1.892857143    0.833333333    -3.666666667    0
-3.25    -0.773809524    -0.785714286    3.952380952    1.892857143    4.833333333    -0.666666667    -9
-5.25    0.226190476    -0.785714286    -0.047619048    1.892857143    4.833333333    0.333333333    -4
-4.25    -0.773809524    -0.785714286    -5.047619048    1.892857143    0.833333333    -1.666666667    -6
-1.25    -0.773809524    -0.785714286    -6.047619048    1.892857143    2.833333333    -5.666666667    0
-1.25    0.226190476    -0.785714286    -6.047619048    1.892857143    0.833333333    -4.666666667    -4
2.75    2.226190476    2.214285714    0.952380952    1.892857143    -1.166666667    5.333333333    2
0.75    1.226190476    0.214285714    13.95238095    6.892857143    0.833333333    3.333333333    -2
-0.25    -0.773809524    -2.785714286    3.952380952    1.892857143    2.833333333    2.333333333    0
-0.25    -0.773809524    -5.785714286    5.952380952    -0.107142857    1.833333333    -1.666666667    0
-2.25    -0.773809524    -4.785714286    -2.047619048    -2.107142857    1.833333333    -1.666666667    0
-1.25    -0.773809524    0.214285714    -6.047619048    -0.107142857    1.833333333    -2.666666667    0
-0.25    -1.773809524    -4.785714286    -1.047619048    3.892857143    -0.166666667    0.333333333    0
-1.25    -2.773809524    -4.785714286    -5.047619048    0.892857143    -2.166666667    -3.666666667    0
-1.25    -1.773809524    -6.785714286    -3.047619048    0.892857143    -2.166666667    -3.666666667    0
-1.25    -0.773809524    -1.785714286    1.952380952    -0.107142857    -2.166666667    -3.666666667    3
-1.25    -1.773809524    -1.785714286    1.952380952    -3.107142857    -2.166666667    -2.666666667    0
-1.25    -1.773809524    -0.785714286    -1.047619048    -3.107142857    -2.166666667    -5.666666667    0
-1.25    1.226190476    -0.785714286    5.952380952    -2.107142857    -1.166666667    2.333333333    0
-4.25    -1.773809524    -0.785714286    8.952380952    3.892857143    0.833333333    2.333333333    0
-2.25    -0.773809524    -0.785714286    5.952380952    4.892857143    1.833333333    1.333333333    0
-1.25    -0.773809524    -0.785714286    0.952380952    4.892857143    1.833333333    -1.666666667    0
0.75    -0.773809524    -0.785714286    1.952380952    3.892857143    -0.166666667    1.333333333    0
-0.25    0.226190476    -0.785714286    0.952380952    -0.107142857    1.833333333    0.333333333    0
-0.25    -0.773809524    -0.785714286    -0.047619048    0.892857143    -2.166666667    -3.666666667    0
-1.25    -0.773809524    -0.785714286    -6.047619048    -4.107142857    -1.166666667    -4.666666667    0
-1.25    -2.773809524    -0.785714286    -6.047619048    -6.107142857    -2.166666667    -5.666666667    0
-1.25    -0.773809524    -0.785714286    -6.047619048    -5.107142857    -1.166666667    -2.666666667    0
-2.25    -1.773809524    -0.785714286    -6.047619048    -5.107142857    -1.166666667    -3.666666667    0
-2.25    -1.773809524    -0.785714286    -6.047619048    -4.107142857    1.833333333    -2.666666667    3
-4.25    1.226190476    -0.785714286    -6.047619048    -5.107142857    -1.166666667    2.333333333    0
-2.25    0.226190476    0.214285714    6.952380952    4.892857143    2.833333333    4.333333333    0
-0.25    0.226190476    1.214285714    3.952380952    6.892857143    2.833333333    3.333333333    0
-1.25    1.226190476    0.214285714    0.952380952    7.892857143    1.833333333    2.333333333    0
-1.25    0.226190476    -0.785714286    -5.047619048    6.892857143    1.833333333    1.333333333    0
0.75    -0.773809524    -0.785714286    5.952380952    6.892857143    -0.166666667    1.333333333    1
-1.25    -1.773809524    -0.785714286    0.952380952    3.892857143    -2.166666667    -1.666666667    1
-1.25    -3.773809524    -0.785714286    -3.047619048    -1.107142857    -2.166666667    -3.666666667    0
-1.25    -1.773809524    -0.785714286    -0.047619048    -5.107142857    -4.166666667    -3.666666667    0
-1.25    -1.773809524    -0.785714286    -1.047619048    -5.107142857    -2.166666667    -3.666666667    0
-1.25    -1.773809524    -0.785714286    3.952380952    -4.107142857    -0.166666667    -4.666666667    0
-1.25    -0.773809524    -0.785714286    -6.047619048    -8.107142857    -1.166666667    -3.666666667    0
-1.25    -0.773809524    -0.785714286    -6.047619048    1.892857143    -1.166666667    -4.666666667    0
-1.25    -0.773809524    -0.785714286    -1.047619048    -5.107142857    -1.166666667    -3.666666667    0
-1.25    -0.773809524    -0.785714286    -1.047619048    -5.107142857    -4.166666667    -3.666666667    -7
-1.25    -0.773809524    -0.785714286    -3.047619048    -5.107142857    -6.166666667    -3.666666667    -6
-1.25    -0.773809524    -0.785714286    -4.047619048    -5.107142857    -6.166666667    -3.666666667    -8
-0.25    -0.773809524    -0.785714286    -6.047619048    -5.107142857    -5.166666667    -3.666666667    -8
0.75    3.226190476    2.214285714    -6.047619048    5.892857143    4.833333333    5.333333333    -6
3.75    7.226190476    7.214285714    13.95238095    11.89285714    6.833333333    6.333333333    3
4.75    7.226190476    6.214285714    1.952380952    10.89285714    6.833333333    5.333333333    3
3.75    8.226190476    2.214285714    4.952380952    7.892857143    4.833333333    6.333333333    5
4.75    7.226190476    2.214285714    7.952380952    7.892857143    4.833333333    7.333333333    3
4.75    7.226190476    2.214285714    10.95238095    8.892857143    6.833333333    7.333333333    5
2.75    -0.773809524    -1.785714286    2.952380952    6.892857143    -6.166666667    7.333333333    5
-1.25    -1.773809524    -0.785714286    -1.047619048    -0.107142857    -5.166666667    3.333333333    -6
-1.25    -1.773809524    -0.785714286    -0.047619048    -4.107142857    -4.166666667    1.333333333    -3
-1.25    -1.773809524    -0.785714286    -4.047619048    -6.107142857    -4.166666667    -1.666666667    -2
1.75    -1.773809524    -0.785714286    -6.047619048    -6.107142857    -4.166666667    -2.666666667    -3
1.75    -1.773809524    -0.785714286    -6.047619048    -6.107142857    -4.166666667    -3.666666667    -4
-0.25    -1.773809524    -0.785714286    -6.047619048    -6.107142857    2.833333333    1.333333333    -3
5.75    3.226190476    2.214285714    11.95238095    9.892857143    4.833333333    2.333333333    7
5.75    5.226190476    3.214285714    13.95238095    11.89285714    6.833333333    5.333333333    5
4.75    5.226190476    4.214285714    5.952380952    11.89285714    7.833333333    6.333333333    5
5.75    3.226190476    4.214285714    12.95238095    10.89285714    7.833333333    7.333333333    5
4.75    5.226190476    3.214285714    -1.047619048    10.89285714    8.833333333    7.333333333    7
2.75    -1.773809524    2.214285714    -3.047619048    7.892857143    -6.166666667    6.333333333    9
-1.25    -2.773809524    -0.785714286    -6.047619048    2.892857143    -6.166666667    -1.666666667    -3
-2.25    -2.773809524    -0.785714286    -6.047619048    -8.107142857    -6.166666667    -3.666666667    -4
-1.25    -2.773809524    -0.785714286    -6.047619048    -1.107142857    -5.166666667    -3.666666667    -4
-2.25    -2.773809524    -0.785714286    -6.047619048    -6.107142857    -4.166666667    -3.666666667    -3
-2.25    -2.773809524    -0.785714286    -6.047619048    -7.107142857    -5.166666667    -3.666666667    -3
-2.25    -1.773809524    -0.785714286    -6.047619048    -0.107142857    -5.166666667    1.333333333    3
1.75    2.226190476    1.214285714    -6.047619048    -8.107142857    2.833333333    3.333333333    5
4.75    3.226190476    4.214285714    -6.047619048    -7.107142857    5.833333333    6.333333333    6
4.75    3.226190476    5.214285714    9.952380952    -8.107142857    4.833333333    7.333333333    8
6.75    3.226190476    6.214285714    10.95238095    -6.107142857    6.833333333    8.333333333    7
6.75    3.226190476    6.214285714    13.95238095    -6.107142857    8.833333333    4.333333333    9
5.75    4.226190476    6.214285714    13.95238095    -5.107142857    2.833333333    4.333333333    9
1.75    -6.773809524    -0.785714286    -6.047619048    -4.107142857    -0.166666667    -2.666666667    -6
-1.25    -1.773809524    -0.785714286    -6.047619048    -6.107142857    -5.166666667    -3.666666667    -6
-2.25    -2.773809524    -0.785714286    -6.047619048    -6.107142857    -6.166666667    -5.666666667    -6
-2.25    -2.773809524    -0.785714286    -6.047619048    -7.107142857    -5.166666667    -4.666666667    -3
-2.25    -1.773809524    -0.785714286    -6.047619048    -7.107142857    -6.166666667    -4.666666667    0

That works fine for me

$ awk '{ print $3 }' xl.txt | more
161
PGP_JFY63
COC084
Addicts
M
42
-0.785714286
-0.785714286
-0.785714286
-0.785714286
-0.785714286
-0.785714286
2.214285714
0.214285714
-2.785714286
-5.785714286
-4.785714286
0.214285714
-4.785714286

Are you sure your text file is in plain text format? Run this:

wc -l filename.txt

when I do:

wc -l filename.txt

I get

0 filename.txt

OK, so I suspect the file is not in plain text format or doesn't contain any valid newline characters. Excel might have exported it in the wrong format.

Try the following

tr "\r" "\n" < filename.txt > newfilename.txt

And run the awk command again on newfilename.txt.

Thank you again for your help!

I get the following output:

tr "\r" "\n" master_tab_delimited_file.txt > new_master.txt
usage: tr [-Ccsu] string1 string2
       tr [-Ccu] -d string1
       tr [-Ccu] -s string1
       tr [-Ccu] -ds string1 string2

Please, type exactly what mobitron wrote:

tr "\r" "\n" < filename.txt > newfilename.txt

Note the "<" before "filename.txt".

Thanks Shell_life and mobitron! It works now!