awk command to replace columns in 2 files

Hi All,
I already have a code which replaces column 14 of NPBR.XTR.tmp with column 8 of NPBR3G.XTR.final

awk -F'\|' 'FNR==NR{a[$1]= $2"^"$8;next;}a[$2]{split(a[$2],b,"^");$8=b[1];$14=b[2];}1' OFS="|" ${SHTEMP}NPBR3G.XTR.final ${SHTEMP}NPBR.XTR.tmp > ${SHTEMP}NPBR.XTR.final

I also need to replace column 15 of NPBR.XTR.tmp with column 4 of NPBR3G.XTR.final

AND
Replace column 6 of NPBR.XTR.tmp with column 2 of NPBR3G.XTR.final

awk -F\| '
        FNR == NR {
                a[$1] = $2"^"$8"^"$4
                next
        }
        a[$2] {
                split(a[$2],b,"^")
                $8 = b[1]
                $14 = b[2]
                $15 = b[3]
                $6 = b[1]
        }
        1
' OFS="|" ${SHTEMP}NPBR3G.XTR.final ${SHTEMP}NPBR.XTR.tmp
1 Like

To append column names to a table using db2 and shell script
# Get all the columns seperated with comma.
Col_names=$(db2 -x "select colname||',' from syscat.columns where tabname = '$TABLENAME' order by colno")

#Put all the columns in a text file
echo $Col_names > columns.txt

#Export table data to csv which you want to append columns
db2 "EXPORT TO $HOME/$TABLENAME.csv OF DEL MESSAGES $HOME/$TABLENAME.txt select * from $SCHEMA.$TABLENAME"

#Append columns to Table
cat columns.txt $HOME/$TABLENAME.csv > $HOME/newfile.csv