Merging columns

Hi, I have input file.

File1:

Seqno Name
124 name1
121 name2
123 name3
122 name4

We will send the file1 to some other team. They will replace name column with place in file1 and send back to us as file2.

file2:

Seqno Place

124 place1
121 place2
123 place3file2:

And then we will replace the name with place based on row-id and output file should only contain the row-id and place as shown below.

Output:

File1:

Row-id Place
121 place2
122
123 place3
124 place1

Please help me how to do it. Thanks in advance.

Try this:

awk 'NR==FNR{a[$1]=$2;next}{print $1 " " a[$1]}' file2 file1

Regards

Thanks for reply. But when I gave the below command.

awk 'NR==FNR{a[$1]=$2;next}{print $1 " " a[$1]}' file2 file1

The output file is as shown below :

124
121
123
124
121
123
122

I think we have to sort the files and give the above command. Please correct me if Iam wrong.

awk 'NR==FNR{a[$1]=$2;next}{print $1 " " a[$1]}' file2 file1

Works fine for me with the given files.....I get this output:

124 place1
121 place2
123 place3
122 

You should use nawk or /usr/xpg4/bin/awk on Solaris.

Thanks a lot...... I have given gawk instead of awk its working now........ Thanks again.....................