one-liners

Everyone loves on-liners, right? No, not those awful puns and jokes your coworkers bother you with, but near-magic on-line commands for the linux / unix command line interface!
Here's a few I've collected over the past couple years at work that occasionally make my life easier. A lot of these are awk on-liners, or just some bash on-liners. I also occasionaly find myself using ruby or perl for on-liners, but I haven't "Saved" many of those. I'll try to remember to start "saving" them here. 
 
Used this to pull hostnames out of a CSV file with URLs in it. The file was a CSV
gawk -F, '{site[gensub(/"?http:\/\/([a-zA-Z0-9_\.-]+)\/.*/, "\\1","g", $3)]++} END {for (n in site) {print n}}' FILENAME  

generate random keys / passwords -- fold it at 9 characters, and give me 10 lines of output. 
cat /dev/urandom | tr -dc "a-zA-Z0-9-_\$"|fold -w 9|head

count destination addresses from the output of "show conn" on the PIX/ASA -- This is probably not as useful to other folks. 
cat conn | sort -k3 | awk '{sub(/:[0-9]*/,""); arr[$3]++} END { for ( n in arr ) {print arr[n]"\t"n } }' | sort -n

count occurrences of things with awk, example, MAC addresses in an ARP table to find NATs or VMs.
awk '{ macs[$4]++; } END{ for (i in macs) { print i, macs[i]; } }' FILENAME

Ping IPs in a file and report UP / DOWN
for i in `cat FILENAME_WITH_IPS`; do echo -n "$i "; if ping -q -w2 $i 2>&1 >/dev/null; then echo "UP"; else echo "DOWN"; fi; done

Get / calculate interface utilization w/ SNMP from a Csco device. 
while :; do A=$(snmpget -c "public" -v 2c IP .1.3.6.1.2.1.2.2.1.16.268 | awk -F": " '{print $2}'); sleep 10 ; B=$(snmpget -c "public" -v 2c IP .1.3.6.1.2.1.2.2.1.16.268 | awk -F": " '{print $2}'); C=$(( $(( $(($B - $A)) * 800 )) / 10000 )); echo $C; sleep 20; done

count lines of code in a directory
find /usr/lib/perl5/ -name \*.pm | while read file; do echo -n "$file "; sed '/^[ \t]*$/d; /^[ \t]*#/d' $file | wc -l; done | awk '{t = t + $2; print $2 "\t" $1} END {print t "\tTOTAL"}'