ç°¡åãªè§£æã¯ã¯ã³ã©ã¤ãã¼ã§ãã£ã¡ããããã¨ãããã¨ã§ã¾ãã¯ç°¡åã«æå°å¤ã¨æ大å¤ã¨å¹³åãæ±ããAwkã¯ã³ã©ã¤ãã¼ãæ¸ãã¾ãã
ãã¨ãã°ä»¥ä¸ã®ãããªãã°ãã¡ã¤ã«ãããã¨ãããåã¯ãã¾ã3åç®ã®æ°å¤ã«å¯¾ãã¦çµ±è¨å¤ãåºãããã®ã ã
0 0 147.086 0 10 141.269 0 20 10000 0 30 2805.22 0 40 152.003 0 50 144.762 0 60 144.926
æ大å¤
cat test.log | awk '{if(m<$3) m=$3} END{print m}'
{ if(m<$3) m=$3 } END { print m }
$3ã£ã¦ã®ã第3çªç®ã®åã¨ããæå³ãªã®ã§ããããå¤ããã°å¥ã®ã¨ãããåç §å¯è½ãBEGINã®ä¸ã§åæå¤ãè¨å®ããå¿ è¦ãããã®ããªã¨æã£ã¦ãããã©ããããªãif(m>$3)ãå®éã«ãã£ã¦ã¿ãã大ä¸å¤«ã ã£ãã
æå°å¤
åºæ¬çã«ã¯åããä¸çå·ãå¤ããã ãã
cat test.log | awk 'BEGIN{m=100000}{if(m>$3) m=$3} END{print m}'
{ if(m>$3) m=$3 } END { print m }
æ大å¤ã®å ´åã¯ï¼ç©ºç½ãããæ°å¤ã大ããã®ã§ï¼å¤§ä¸å¤«ã ããæå°å¤ã®å ´åã¯ãã¡ãæå°å¤ä»¥ä¸ã®åæå¤ãè¨å®ããå¿ è¦ãããã
åè¨
cat test.log | awk '{m+=$3} END{print m;}'
{ m+=$3 } END{ print m; }
å¹³å
åè¨ãå¿ç¨ãã¦ENDã®ä¸ã§é©å½ã«ããããåãã°ããããªãã¨ãã§ããã
cat test.log | awk '{m+=$3} END{print m/NR;}'
{ m+=$3 } END{ print m/NR; }
ä¸å¤®å¤
ã¨ã¦ãé¢åã ã£ããã¯ã³ã©ã¤ãã¼ã«ã¯åãã¦ãªãæ°ããããæ£æ»æ³ãããã®ããªâ¦ã
cat test.log | awk '{print $3}' | sort | awk -v l=`a=(\`wc -l test.log\`); expr ${a[0]} / 2` 'NR==l{print $1}'
sortã§ä¸¦ã¹æ¿ããå¾ãwcã³ãã³ãã§è¡æ°ãåå¾ãã¦2ã§å²ããawkã®ã·ã§ã«å¤æ°ãå°å
¥ãããªãã·ã§ã³-vã使ã£ã¦çãä¸ã®è¡ã®æ°å¤ãæ¸ãåºããã¨ããæµããexprã³ãã³ããå°æ°ãæ±ããªãã®ã§2ã§å²ãã¨åãæ¨ã¦ã«ãªãã®ã§ãå¥æ°è¡ã®æã¯ä¸å¤®ããä½ãæ¹ã«ä¸ã¤ãããå¤ã¨ãªãã
è£è¶³
ã¡ãªã¿ã«ã空ç½è¡ããã£ããã³ã¡ã³ãè¡ãããã¨ãã¾ãåããªãã
空ç½è¡ã¯ä¾ãã°å¹³åã®æã¯ä»¥ä¸ã®æ¹æ³ã§ä½ã¨ããªãã¿ãããNFã使ãã
NF>0{ m+=$3 } END { print m/NR }