Help with Combining Content of Two files

I'm trying to combine it using awk but still can't figure it out. Here is the file.

cat file1.txt
Mr Smith

Mr John

Ms Linda

cat file2.txt
No 4 Jln Empat
Kuala Lumpur

No 213 Tmn Bunga
Kedah

No 1 Kampung Bukit
Malaysia

I want to combine this file1 and file2 so the output will be:

Mr Smith
No 4 Jln Empat
Kuala Lumpur

Mr John
No 213 Tmn Bunga
Kedah

Ms Linda
No 1 Kampung Bukit
Malaysia

Anybody please help me...:frowning:

Can you show us what you have tried with awk?

Regards

I try this script, but it says "awk: fatal: can't open source file `BEGIN {"

script:
#!/bin/sh
DATA1=file1.txt
DATA2=file2.txt

awk -f 'BEGIN {
while ((getline < "'$DATA2'") > 0)
f2array[$2] = $1
OFS=","}

{if (f2array[$1])
print f2array[$1],$2,$3,$4,$5
}' $DATA1

Thanks for your time to read my thread Franklin :o

if you have Python

#!/usr/bin/env python
file1=open("file1").read().split("\n")
file1=[i for i in file1 if i.strip() !="" ]
file2=open("file2").read().split("\n\n")
for item in zip(file1,file2):
    print item[0],"\n",''.join(item[1]),"\n"

output

# ./test.py
Mr Smith
No 4 Jln Empat
Kuala Lumpur

Mr John
No 213 Tmn Bunga
Kedah

Ms Linda
No 1 Kampung Bukit
Malaysia

Assuming the lines are not separated by a blanc line in your files:

awk '{
  print
  getline s < "file2.txt"; print s
  getline s < "file2.txt"; print s
  print ""
}' file1.txt

Regards

Thanks Ghostdog! :rolleyes: