搜索文本

编程入门 行业动态 更新时间:2024-10-27 09:39:44
本文介绍了搜索文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图编写一个shell脚本来搜索文件中的文本并将文本和相关信息打印到单独的文件中。

I'm trying to write a shell script that searches for text within a file and prints out the text and associated information to a separate file.

从这个包含基因ID列表的文件:

From this file containing list of gene IDs:

DDIT3 ENSG00000175197 DNMT1 ENSG00000129757 DYRK1B ENSG00000105204

我想搜索这些基因ID( ENSG *),它们在一个gtf文件中的RPKM1和RPKM2值:

I want to search for these gene IDs (ENSG*), their RPKM1 and RPKM2 values in a 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 it to a separate output file

Gene_ID RPKM1 RPKM2 ENSG00000108270 7.81399 8.149 ENSG00000101126 12.0082 8.55263

我在命令行上为每个ID使用了它:

I've done it on the command line using for each ID using:

grep -w "ENSGno" rnaseq.gtf| awk '{print $10,$13,$14,$15,$16}' > output.file

但是在编写shell脚本时,我尝试了各种各样的for ,同时,阅读,做和改变变量,但没有成功。任何想法都会很棒!

but when it comes to writing the shell script, I've tried various combinations of for, while, read, do and changing the variables but without success. Any ideas would be great!

推荐答案

您可以这样做:

You can do something like:

while read line do var=$(echo $line | awk '{print $2}') grep -w "$var" rnaseq.gtf| awk '{print $10,$13,$14,$15,$16}' >> output.file done < geneIDs.file

更多推荐

搜索文本

本文发布于:2023-10-19 19:28:03,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!