How to add data from 2 input files and save it in 1 output file

Hi,

i have 2 input files which are file1.txt and file2.txt. I need to extract data from file1.txt and file2.txt and save it in file3.txt like example below:-

File1.txt
ID scrap1
Name scrap1
start 1
end 10

ID scrap2
Name scrap2
start 11
end 15

ID scrap3
Name scrap3
start 20
end 70

File2.txt
N size1.pf size1.fna
N size2.pf size2.fna
N size3.pf size3.fna

the input are from 2 different files and the output should be in file3.txt and should have as follows:-

File3.txt
scrap1 scrap1 N size1.pf size1.fna
scrap2 scrap2 N size1.pf size1.fna
scrap3 scrap3 N size1.pf size1.fna

the first 2 columns has the same data but for different field which are ID and Name. How to do this in perl or sed? i have more than 10k data to deal with in this way. appreciate if u could help on this. thanks

awk 'NR!=FNR{print L[FNR],$0; next} $1=="ID"{I=$2}
    $1=="Name"{L[++p]=I FS $2}' file1.txt file2.txt > file3.txt

hi,

thanks for your reply... It works...but it just show the first line only.. :frowning:

Funny, it's working fine here:

$ awk 'NR!=FNR{print L[FNR],$0; next} $1=="ID"{I=$2}
    $1=="Name"{L[++p]=I FS $2}' file1.txt file2.txt > file3.txt
$ cat file3.txt
scrap1 scrap1 N size1.pf size1.fna
scrap2 scrap2 N size2.pf size2.fna
scrap3 scrap3 N size3.pf size3.fna

Which first line is it printing? Are you on solaris, try nawk instead of awk

no, i'm just using ubuntu..i'm new in this scripting stuff. i did try your script again and again just now but i got the same result. it just give me 1 row instead of 3 rows like u did..