Tag: awk
-
Parse Apache access logs to get all ips
Don’t use it as a way to count visits, as all these ips are not real visits, but bots, crawlers, etc. cat access.log | grep -o ‘\([0-9]\{23\}.\)\{3\}\.[0-9]\{23\}’ | sort | uniq | wc -l
-
Deleting Blank Lines Using AWK
Here’s the trick: cat /tmp/test | awk ‘NF > 0’ > /tmp/test1
-
Format find and awk output locating large files
Use find to locate files over a criteria size and format output with awk. Changing value of NF variable you change fields separator find / -type f -size +20000k -exec ls -lh {} \; | awk ‘{ print $NF “: ” $5 }’
-
Analyze history for most used commands
With history and a little bit of awk we make the magic. List commands in history by usage. Two examples above, the simple one and the advanced where the arguments to the commands are shown. history | awk ‘{a[$2]++}END{for(i in a){print a[i] ” ” i}}’ | sort -rn | head #Advanced version history |…