Thank you Pat...
This is definitely not a homework problem....I work for a bank and we have to do something like this....Since, I am not an expert in awk, I was trying to achieve it through something like this...
Code:
#!/usr/bin/ksh
DIR=$1
CODES_FILE=$2
METADATA_FILE=$3
cd ${DIR}
sort -k 2,2 ${CODES_FILE} > f1.dat
sort -k 2,2 ${METADATA_FILE} > f2.dat
awk '
BEGIN { OFS = "\t" } { print $2 , $1, $2 }
' f1.dat > temp_f1.dat
awk '
BEGIN { OFS = "\t" } { print $2 , $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27 }
' f2.dat > temp_f2.dat
join -j1 1 -j2 1 -o 1.2 1.3 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 2.18 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 temp_f1.da
t temp_f2.dat | tr -s ' ' '\t' > f3.dat
The reason why I didn't like this is because File2 has dynamically changing columns. The current code takes only 27 fields and if I have 80 fields, then it would be a problem.
File 1 is always constant and has only 2 columns.
Please advice