linux - Searching for text -
i'm trying write shell script searches text within file , prints out text , associated information separate file.
from file containing list of gene ids:
ddit3 ensg00000175197 dnmt1 ensg00000129757 dyrk1b ensg00000105204
i want search these gene ids (ensg*), rpkm1 , rpkm2 values in gtf file:
chr16 gencodev7 gene 88772891 88781784 0.126744 + . gene_id "ensg00000174177.7"; transcript_ids "enst00000453996.1,enst00000312060.4,enst00000378384.3,"; rpkm1 "1.40735"; rpkm2 "1.61345"; iidr "0.003"; chr11 gencodev7 gene 55850277 55851215 0.000000 + . gene_id "ensg00000225538.1"; transcript_ids "enst00000425977.1,"; rpkm1 "0"; rpkm2 "0"; iidr "na";
and print/ write separate output file
gene_id rpkm1 rpkm2 ensg00000108270 7.81399 8.149 ensg00000101126 12.0082 8.55263
i've done on command line using each id using:
grep -w "ensgno" rnaseq.gtf| awk '{print $10,$13,$14,$15,$16}' > output.file
but when comes writing shell script, i've tried various combinations of for, while, read, , changing variables without success. ideas great!
you can like:
while read line var=$(echo $line | awk '{print $2}') grep -w "$var" rnaseq.gtf| awk '{print $10,$13,$14,$15,$16}' >> output.file done < geneids.file
Comments
Post a Comment