Saturday, September 12, 2009

Linux Tip/Tricks continue...

To print unique IPs from squid access.log and sort them
awk '{print $3}' /var/log/squid/access.log.0 | sort -ut . -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 | nl

This one doesn't sort but gives uniq ips with line number.
awk '{print $3}' /var/log/squid/access.log.0 | sort -u | nl

To put some text on every blank line
sed 's/^/some text/' urls > newfile

To kill the process
ps -ef | grep xterm | awk '{print $2}' | xargs kill -9

Check if the machine is live, useful for use in scripts.
if ping -c 1 >/dev/null 2>&1; then echo "live";else echo "dead";fi

No comments:

Post a Comment