如何拔出匹配从另一个文件输出到不同的行每行一个文件的所有行? [英] How to pull out all lines of a file matching each line from another file and output into separate rows?

查看:153
本文介绍了如何拔出匹配从另一个文件输出到不同的行每行一个文件的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个类似的问题什么一直previously要求(参见下面的链接),但是这一次,我想输出字符串常见到行而不是列如下图所示:

This is a similar question to what has been previously asked (see below for link) but this time I would like to output the common strings into rows instead of columns as shown below:

我有两个文件,​​每个文件一列看起来像这样的:

I have two files, each with one column that look like this:

文件1

chr1 106623434
chr1 106623436
chr1 106623442
chr1 106623468
chr1 10699400
chr1 10699405
chr1 10699408
chr1 10699415
chr1 10699426
chr1 10699448
chr1 110611528
chr1 110611550
chr1 110611552
chr1 110611554
chr1 110611560

文件2

chr1 1066234
chr1 106994
chr1 1106115

我要搜索文件1,拉出了与文件2,输出1线的精确匹配都在它自己的行相匹配的所有行。然后,我想要做的文件2的2线等相同,直到文件2的所有比赛都在文件1,并输出到它自己的行被发现。另外,我有非常大的文件,这样的东西,将不需要的文件2被完全存储在内存中的工作,否则将无法运行完成。希望输出将是这个样子:

I want to search file 1 and pull out all lines that are an exact match with line 1 of file 2 and output all matches on it's own line. Then I want to do the same for line 2 of file 2 and so on until all matches of file 2 have been found in file 1 and output to it's own row. Also I am working with very large files so something that won't require file 2 to be completely stored in memory, otherwise it will not run to completion. Hopefully the output will look something like this:

chr1 106623434  chr1 106623436  chr1 106623442  chr1 106623468
chr1 10699400   chr1 10699405   chr1 10699408   chr1 10699415   chr1 10699426  chr1 10699448 
chr1 110611528  chr1 110611550  chr1 110611552  chr1 110611554  chr1 110611560  

类似的问题在:
<一href=\"http://stackoverflow.com/questions/32871779/how-to-move-all-strings-in-one-file-that-match-the-lines-of-another-to-columns-i/32872383?noredirect=1#comment54885204_32872383\">How移动在一个文件中的另一列线匹配的输出文件?

推荐答案

只要你的模式并不完全重合这应该工作

as long as your patterns don't overlap completely this should work

$ while read p; do grep "$p" file1 | tr '\n' '\t'; echo "";  done < file2
chr1 106623434  chr1 106623436  chr1 106623442  chr1 106623468
chr1 10699400   chr1 10699405   chr1 10699408   chr1 10699415   chr1 10699426   chr1 10699448
chr1 110611528  chr1 110611550  chr1 110611552  chr1 110611554  chr1 110611560

这篇关于如何拔出匹配从另一个文件输出到不同的行每行一个文件的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆