Let's say I have a file that contains these lines:02.03.14    14.50   14.50   0.00    Desc02.03.14    17.00   0.00    17.00   Desc01.03.14    2.82    1.68    calc    Desc02.03.14    1.04    0.00    1.04    Desc06.03.14    6.00    0.00    6.00    Desc08.03.14    11.76   2.98    calc    Desc10.03.14    3.27    0.00    3.27    DescI want to replace all column entries containing calc (only appearing in the 4th column) to contain the difference between the 3nd and 2nd column, so 4th=3rd-2nd.How can I do so?
Replace column entry with sum of other column entries
text processing;sed;awk
Sed can't do arithmetic. Use awk instead.awk '    $4 == calc {sub(/calc(  |\t)/, sprintf(%-6.2f, $3 - $2))}    1'The 1 at the end means to print everything (after any preceding transformation). Instead of the text substitution with sub, you could assign to $4, but doing so replaces inter-column space (which can be any sequence of spaces and tabs) by a single space character. If your columns are tab-separated, you can useawk '    BEGIN {ORS = \t}    $4 == calc {$4 = sprintf(%.2f, $3 - $2))}    1'  Yes, yes, technically it can since it's Turing-complete. But not in any sane way.  