-
Notifications
You must be signed in to change notification settings - Fork 3
/
col_weigh.awk
executable file
·73 lines (65 loc) · 1.86 KB
/
col_weigh.awk
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/awk -f
function synopsis_show() {
printf("\n");
printf("NAME\n");
printf("\n");
printf("\tcol_weigh.awk\n");
printf("\n");
printf("SYNOPSIS\n");
printf("\n");
printf("\tawk -f col_weigh.awk\t\t\t\t\\\n");
printf("\t\t\t [-v <var2>=<val2>\t\t\\\n");
printf("\t\t\t -v <varN>=<valN>]\t\t\\\n");
printf("\t\t\t <fileToProcess>\n");
printf("\n");
printf("DESCRIPTION\n");
printf("\n");
printf("\t'col_weigh.awk' is a simple awk script that accepts as input\n");
printf("\ta column dominant array of numbers, and returns for each colum\n");
printf("\tits values weighed by the column index.\n");
printf("\n");
printf("ARGUMENTS\n");
printf("\n");
printf("\tThe following variables passed with -v <var>=<val>\n");
printf("\tprogram behaviour:\n");
printf("\n");
printf("\t-v width=<cellWidth>\n");
printf("\tSet the display cell width to <cellWidth>. Default is 12.\n");
printf("\n");
printf("\t-v prec=<precision>\n");
printf("\tSet the display precision to <precision>. Default is 4.\n");
printf("\n");
printf("EXAMPLES\n");
printf("\n");
printf("\tTo process a file, say 'lh_calc.log' that contains a 'matrix'\n");
printf("\tsimply do a\n");
printf("\n");
printf("\t\t$>col_weigh.awk lh_calc.log\n");
printf("\n");
printf("\tor even\n");
printf("\n");
printf("\t\t$>cat lh_calc.log | col_weigh.awk\n");
printf("\n");
printf("\n");
}
BEGIN {
if(!width) width = 12;
if(!precision) precision = 4;
if(help) {
synopsis_show();
exit(0);
}
}
#
# Main function
#
{
# Populate each matrix entry 't' with '100*(1 - t)'
for(col=1; col<=NF; col++) {
f_result = $col * (1+(col-1)/10);
printf("%*.*f", width, precision, f_result);
}
printf("\n");
}
END {
}