linux - 如何使用合并命令将此文本文件中的 5 行与另一个文本文件中的 1 行合并?

标签 linux bash merge

摘要我有一个 1.txt,其顺序如下:

HLA-A1
HLA-A2
HLA-A3
HLA-A4
.
.
.

另一个 2.txt 的顺序如下(行号=“2/3”是不变的,只是外显子行发生了变化)

exon 1..2
/number="2"
exon 3..4
/number="3"

exon 6..7
/number="2"
exon 4..7
/number="3"

exon 9..31
/number="2"
exon 25..134
/number="3"

exon...

如何使用 merge 命令或其他命令将 2.txt 中的 5 行与 1.txt 中的 1 行合并,最终结果如下:

HLA-A1 exon 1..2 /number="2" exon 3..4 /number="3"
HLA-A2 exon 6..7 /number="2" exon 4..7 /number="3"
HLA-A3 exon 9..31 /number="2" exon 25..134 /number="3"
HLA-A4 ...
.
.

非常感谢您的帮助!

最佳答案

学习 awk 并熟悉该程序,儿子:

$ awk 'NR==FNR{a[FNR]=$0;next}{print a[FNR],$1,$2,$3,$4}' file1 RS="" FS="\n" file2

输出:

HLA-A1 exon 1..2 /number="2" exon 3..4 /number="3"
HLA-A2 exon 6..7 /number="2" exon 4..7 /number="3"
HLA-A3 exon 9..31 /number="2" exon 25..134 /number="3"
HLA-A4 exon...   

关于linux - 如何使用合并命令将此文本文件中的 5 行与另一个文本文件中的 1 行合并?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58350373/

相关文章:

linux - 在 linux 和 mac 机器上通过 ssh 登录运行 GNU Parallel

git - 使用 git 对整个文件进行 'accept theirs' 或 'accept mine' 的简单工具

linux - 如何将 hdfs 文件复制到另一台服务器 [linux]

c - Linux ioctl命令在用户空间和内核空间之间变化

linux - 在 Linux 中删除包含这两种模式的行

linux - 拦截输入设备发送的数据

git - 使用 Sourcetree 命名 merge

java - itext 7 (java) 在新页面上将图像添加到现有 pdf 文档的末尾

linux - 在用户选择的文件中查找单词的 Shell 脚本

c++ - SCons:如何让库获取 CPPPATH 选项