2 ms·
Any programming language with a line- and field-based orientation should do it. Awk is easy because of the implied input loop over the data, and the ability to
by dredmorbius 9y ago
Any programming language with a line- and field-based orientation should do it. Awk is easy because of the implied input loop over the data, and the ability to slice by columns.
If you want additional outputs, you simply create them. For a trivial example, if you've got a list of revenues and expenses (say, by month), and want a report with monthly and annual totals (I'll assume only one year is fed, though the example could be expanded:
#!/usr/bin/gawk -f
BEGIN { printf( "%-8s %-8s | %-8s\n", "revenue", "costs", "profit" )}
{
rev = $1; cost = $2; profit = rev - cost;
totrev+=rev; totcost+=cost;
printf( "%8.2f %8.2f | %8.2f\n", rev, cost, profit )
}
END {
printf( "----------------------------\n")
printf( "%8.2f %8.2f | %8.2f\n", totrev, totcost, totrev - totcost )
printf( "============================\n")
}
That's the equivalent of a spreadsheet with columns for revenues, costs, and profits, with a summary line. But you can run it over any annual datasource.
Now let me check if that's right.... OK, not too far off, though yes, I'd goofed bits (the first time).