Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to merge 2 files using awk 1

Status
Not open for further replies.

anirvir

Technical User
Jul 1, 2009
3
0
0
US
I want to join file1 and file2 as shown in file3 using awk. Can anyone help me?

file1

/prod11idbf/oradata/PROD11i/CSSDM.dbf
/prod11idbf/oradata/PROD11i/abmd01.dbf
/prod11idbf/oradata/PROD11i/abmx01.dbf
/prod11idbf/oradata/PROD11i/ahld01.dbf
/prod11idbf/oradata/PROD11i/ahlx01.dbf


file2

/devdbf/oradata/DEV/CSSDM.dbf
/devdbf/oradata/DEV/abmd01.dbf
/devdbf/oradata/DEV/abmx01.dbf
/devdbf/oradata/DEV/ahld01.dbf
/devdbf/oradata/DEV/ahlx01.dbf



I want file3

/prod11idbf/oradata/PROD11i/CSSDM.dbf /devdbf/oradata/DEV/CSSDM.dbf
/prod11idbf/oradata/PROD11i/abmd01.dbf /devdbf/oradata/DEV/abmd01.dbf
/prod11idbf/oradata/PROD11i/abmx01.dbf /devdbf/oradata/DEV/abmx01.dbf
/prod11idbf/oradata/PROD11i/ahld01.dbf /devdbf/oradata/DEV/ahld01.dbf
/prod11idbf/oradata/PROD11i/ahlx01.dbf /devdbf/oradata/DEV/ahlx01.dbf

I found one thread having following command

awk '
NR==1{for(i=1;i<NF;++i)n1=" na"n1}
NR==FNR{a1[$1]=substr($0,length($1)+1);t[$1];next}
FNR==1{for(i=1;i<NF;++i)n2=" na"n2}
{a2[$1]=substr($0,length($1)+1); t[$1]; next}
END {for(i in t)print i (i in a1 ? a1 : n1) (i in a2 ? a2 : n2) | "sort"}
' file1 file2

But it didn't work for me. I am getting some syntax error near line 6.

Thanks in advance.
 
For parallel merging, in *nix, use paste

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
First of all thank you for answering my easy question. It was really simple but I didn't know paste command.

Second sorry for opening same thread in two different group. I will make sure now on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top