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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge two files...

Status
Not open for further replies.

goyalpdm

Programmer
Jan 11, 2003
42
US
hHi,

I have two pipe-seperated files and need to merge them as follows -

File1 -->
col_11 | col_11
col_12 | col_12
col_13 | col_13

File2 -->
col_AA | col_BA
col_AB | col_BB
col_AC | col_BC

Merged file should as follows ->
col_11 | col_AA | col_BA
col_11 | col_AB | col_BB
col_11 | col_AC | col_BC

col_12 | col_AA | col_BA
col_12 | col_AB | col_BB
col_12 | col_AC | col_BC

col_13 | col_AA | col_BA
col_13 | col_AB | col_BB
col_13 | col_AC | col_BC

Basically, add first column in line 1 from file 1 to all lines of file 2, repeate it for each line in file1.

Appreciate the help.

Thanks !
 
Something like this ?
awk -F'|' '
BEGIN{while((getline<"file2")>0)a[n++]=$0}
{for(i=0;i<n;++i)printf "%s|%s\n",$1,a}
' file1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top