Copy lines by rows in awk -
i have input file contains, per row, value , 2 weights.
i generate 2 output files - value in first column repeated once per line, according weights. best explained short example. if input file is:
file.in:
35 2 0 37 2 3 38 0 4
then generate 2 output files:
file.out1:
35 35 37 37
file.out2:
37 37 37 38 38 38 38
i use these output files calculate average , median of first column according weights in second , third column.
i hope question clear. thank help.
this pretty easy in awk
.
awk '{for(i=0;i<$2;i++) print $1;}' file.in > file.out1
generates first file, and
awk '{for(i=0;i<$3;i++) print $1;}' file.in > file.out2
generates second
it not clear question whether know how compute mean , median these files - seems wanted create these output files. let me know if rest giving trouble, or whether above scripts not clear (i think pretty self-explanatory).
Comments
Post a Comment