简体   繁体   中英

Get awk result greater than X

Command:

grep "redirect=on" access_log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -3

Output is:

34  3.247.44.149
6   5.218.131.185
3   7.173.135.94

Question: How to output only where the NR is greater then 10. In this case:

34  3.247.44.149

I tried already to play with $1 > 10 but $1 is the IP and not the number.

Thank you.

With single awk :

awk -F'[[:space:]]+|?' '$8=="redirect=on"{ a[$1]++ }
     END{ for(ip in a) if(a[ip] > 10) print a[ip],ip }' access_log
  • -F'[[:space:]]+|?' - field separator

  • $8=="redirect=on" - considering only records with query param "redirect=on"

  • a[$1]++ - count same IP address occurrences

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM