Tuesday, May 6, 2008

'Established' connections

I wanted to find out a unique list of IPs currently connected to my Solaris web server.
Here is a quick one liner (not exactly) to do the same.


netstat -an | grep EST | perl -lane '$t{$1}++ if \
$F[1]=~/(\d+\.\d+\.\d+\.\d+)\.\d+/; \
END{foreach $key (sort keys %t) {print $key ;}}'



Duplicate lines

I have a ascii file which seemed to have duplicate lines.

Here is a Perl one liner which will go through the file and prints those duplicate lines once it encounters.


perl -lne 'print if $s{$_}++'