Skip to content
Advertisement

How can I use merge command to merge 5 rows in this text file with 1 row in another text file?

Summary I have a 1.txt with following order like this:

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

And another 2.txt with the order like (the line number=”2/3″ is constant, just the exon line is changed)

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...

How can I use the merge command or another command to merge 5 rows in 2.txt with 1 row in 1.txt to have the final result seem like:

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 ...
.
.

Many thanks for your help!

Advertisement

Answer

Learn awk and get with the program, son:

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

Output:

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...   
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement