Hi All:
I have following files:
File 1:
<header>
text...
text ..
text ..
text ..
<\header>
x
y
z
...
File 2:
<header>
text...
text ..
text ..
text ..
<\header>
1 2 3
11 22 33 .....
I would like to merge these file into a single file as :
x 1 2 3
y 11 22 33 ...
into a single file named File 3.
I am kinda lost on this.
I really appreciate your help.
#!/bin/sh
awk '/header/,/\/header/{next}1' file1 > /tmp/file1.tmp
awk '/header/,/\/header/{next}1' file2 > /tmp/file2.tmp
paste -d" " /tmp/file1.tmp /tmp/file2.tmp > file3
Thanks!!!
I appreciate your help.
awk 'NR==FNR{if(/<\\header/){f=1;next;};if(f)a[++x]=$0}{if(/<\\header/){g=1;next};if(g)print a[++z],$0}' file1 file2
x 1 2 3
y 11 22 33 .....
A couple of one liners that do the same using awk or sed
paste -d" " file1 file2 | awk '/<header>/,/<\\header>/{next}1' > file3
paste -d" " file1 file2 | sed '/<header>/,/<\\header>/d' > file3