Подмножить столбец и разделить на его длину

Tras una inspección visual superficial, su sección options {}parece espartana.

Falta en su interior la directiva listen-oncomo en:

options {
   listen-on port 53 { 192.168.64.1; 127.0.0.1; };
   .....
};

Sin esa directiva, BIND no escuchará en las interfaces previstas.

1
25.07.2019, 23:45
2 ответа

Ни одно из значений в вашем примере не является > 2, поэтому я предполагаю, что вы имеете в виду >= 2.

awk '$1 >= 2 { t++ } END { print t/NR }' myfile

Это будет проходить через каждое значение в первом столбце, если это значение больше или равно 2, мы увеличим переменную t. В конце tбудет разделено на общее количество записей (количество строк )и результат будет напечатан.

Если вы хотите, чтобы уравнение выводилось буквально, вы можете сделать:

awk '$1 >= 2 { t ++ } END { print t"/"NR"="t/NR }' myfile
2
27.01.2020, 23:30

Мы можем использовать утилиту dcдля выполнения вычислений:

$ < myfile  tr -s ' ' '\t' | cut -f1 |
 dc -e "
   [lM lN / p q]sq
   [lM 1 + sM]sa
   [? z0=q lN 1 + sN d2!>a c z0=?]s? 
   4k 0sN l?x
 "

Результат:

.3333

Краткое пояснение:

° Register `N` holds line count.
° Register `M` holds num of lines >= 2.
° Register `q` performs the division, printing it, and quitting. Kinda like the `END` clause of `awk`.
° Register `a` increments the current value stored in register `M`.
° Register `? ` reads the next line from stdin, checks whether it is empty. In case it us then it initiates the end procedure by invoking the q register. Otw, increments register N  the one keeping the line count. Then compares the current line is greater than or equal to 2. Increments reg M if it is. Then calls itself recursively to redo the same set of operations on the next line.
° 4k will set output accuracy to four digits and 0sN shall initialize the line counter, l?x will set the ball rolling recursively. 
0
27.01.2020, 23:30

Теги

Похожие вопросы