从两个文本文件得到公共行 [英] get common lines from two text files
问题描述
我有两个文件。
第一(文件1
)是像这样:
(总有一个text'line前headerline)
The first (file1
) is like so:
(there is always a headerline before a 'text'line)
>random header name1
wonderfulstringwhatsoevergoeson
>random header 2
someotherline
...
另一个文件(文件2
)是文件1
像修改过的文件:
(标题已被删除及行混洗,一个新的报头被添加)
The other file (file2
) is a modifed file of file1
like:
(the header have been removed and the lines are shuffled, a new header has been added)
>name
someotherline
wonderfulstringwhatsoevergoeson
文件1
的每一行(不包括标题)的文件2
出现。
行的文件2
的顺序从文件1
不同。
两个文件都应该留在他们的顺序。
Each line (without the header) of file1
occurs in file2
.
The order of lines in file2
differs from file1
.
Both files should stay in the order they are.
在文件2
输出应该是一样:
(文件2
的头可以忽略不计)
Output should be something alike:
(header of file2
can be ignored)
>random header 2
>random header name1
有没有人线索,该怎么办呢?
Has anybody a clue, how to do so?
最好的问候
推荐答案
$ C $为GNU的 SED :
Code for GNU sed:
$sed '/^[>]/N;s#\(.*\)\n\(.*\)#/\2/s/.*/\1/p#' file1|sed -nf - file2
>random header 2
>random header name1
这篇关于从两个文本文件得到公共行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!