From the expected output, you seem to be adding TAG and VAL columns.
I note your input is not valid CSV. You can not-quote fields, like 12.11, or you can quote fields, like "12.11". Half-quoting them is not valid.
Two ways to do this, including avoiding adding "numeric" values from the column headings. (None of this is tested.)
(a) Define a field separator to match the reality.
awk '-F"[|]"' 'NR == 1 { next; }
{ T3 += $3; T4 += $4; }
END { printf ("T3 %.2f T4 %.2f\n", T3, T4); }'
(b) Fix each field before you use it.
awk '-F|' 'NR == 1 { next; }
{ gsub ("\042", "", $3); T3 += $3; }
{ gsub ("\042", "", $4); T4 += $4; }
END { printf ("T3 %.2f T4 %.2f\n", T3, T4); }'
If this is an example, and you are planning to do this for more columns, I would probably make T into an array, and the addition into a function:
awk '-F|' 'NR == 1 { next; }
function Sum (f) {
gsub ("\042", "", $(f)); T[f] += $(f);
}
{ Sum(2); Sum(3); Sum(5); Sum(11); }
END {
for (f = 1; f < 20; ++f)
if (f in T) printf ("T%d %.2f\n", f, T[f]);
}'
"|"
not|
- when you use|
as the delimiter, the field values become strings like"1.1"
that evaluate numerically to zero – steeldriver Jan 01 '20 at 16:36