I am trying to filter GTEx for liver tissue. I was able to extract the sample names from the "SamplesAtrributesDS.txt" file and find the corresponding column number in the "transcript_expected_count.gct" file for each sample. I then want to use awk to extract the counts from the column number, but I always get this error:

awk: fatal: cannot open file `{print $myvar}' for reading (No such file or directory)

I use the following code:

    #!/bin/bash
    Genes=$(awk -F "\t" '{if ($6=="Liver") print $1}' GTEx_Analysis_v8_Annotations_SampleAttributesDS.txt)
    for gene in $Genes
    do
            colnr=$(head -n 3 GTEx_Analysis_2017-06-05_v8_RSEMv1.3.0_transcript_expected_count.gct | tail -n 1 | cut -f3- | tr '\t' '\n' | cat -n | grep $gene | cut -f 1)
            echo $colnr
            if [ -z "$colnr" ]
            then
                    echo "\$colnr is empty"
            else
                    echo $colnr
                    awk -v myvar=$colnr '{print $myvar}' GTEx_Analysis_2017-06-05_v8_RSEMv1.3.0_transcript_expected_count.gct
            fi
    done

I would be glad if someone can point out what I am doing wrong.
I would do something like this, in python, to filter for the columns of interest.

    #!/usr/bin/env python3
    
    path_ec = "~/Downloads/GTEx_Analysis_2017-06-05_v8_RSEMv1.3.0_transcript_expected_count.gct.gz"
    path_sa = "~/Downloads/GTEx_Analysis_v8_Annotations_SampleAttributesDS.txt"
    
    import pandas as pd
    from itertools import count
    
    SKIP_LINES_GTEx = 2
    SEP = '\t'
    
    df = pd.read_csv(path_sa, sep=SEP)
    ids = df.SAMPID[df.SMTS == "Liver"]
    
    all_cols = pd.read_csv(path_ec, sep=SEP, header=SKIP_LINES_GTEx, nrows=0).columns
    
    # Not all SAMPIDs are in the transcript_expected_count file
    ids = ids[ids.isin(all_cols)]
    
    # Columns to keep
    cols = ['transcript_id', 'gene_id'] + list(ids)
    
    from tempfile import NamedTemporaryFile as TempFile
    with TempFile(mode='w') as out_fd:
    
    # OR:
    # with open(output_filename, mode='w') as out_fd:
    
        print(F"Writing to temporary file {out_fd.name}")
    
        # Lines per chunk
        CHUNKSIZE = 1000
    
        # Read and write chunkwise
        for (df, n) in zip(pd.read_csv(path_ec, sep=SEP, header=SKIP_LINES_GTEx, chunksize=CHUNKSIZE, usecols=cols), count()):
            df.to_csv(out_fd, header=(n == 0), sep=SEP, mode='a', index=None)
    
        input("Done. Press ENTER")

