From 4e80ad2d34f307991562c364b157d1c7a502cd96 Mon Sep 17 00:00:00 2001 From: johannst Date: Fri, 23 Sep 2022 18:29:01 +0000 Subject: deploy: 29c1b6a06f8d5c546fbd5514731c4ac4c504f6c3 --- tools/awk.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tools/awk.html') diff --git a/tools/awk.html b/tools/awk.html index 2b7b348..abcd01b 100644 --- a/tools/awk.html +++ b/tools/awk.html @@ -75,7 +75,7 @@ @@ -253,6 +253,21 @@ done | sort -k2 -n

We capture values from VmRSS and Name into variables and print them at the END once processing all records is done.

+

Capture in array

+
echo 'a 10
+b 2
+b 4
+a 1' | awk '{
+    vals[$1] += $2
+    cnts[$1] += 1
+}
+END {
+    for (v in vals)
+        printf "%s %d\n", v, vals[v] / cnts [v]
+}'
+
+

Capture keys and values from different columns and some up the values. +At the END we compute the average of each key.

Run shell command and capture output

cat /proc/1/status | awk '
                      /^Pid/ {
-- 
cgit v1.2.3