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.
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.