Tuesday, 17 August 2010

Sed & Awk one-liners

Funny how you forget Sed & Awk.  10 years ago I used to know from memory how to use them for quick hand cmd line parses etc.

So as I go along through Solaris admin I thought I'd try and keep a note of them in this posting here.

IP Addresses accessing your FTP server.
cat /var/log/xferlog | awk '{ print $7; }' | sort -u
 
Assigning file next number in sequence 
Generally I copy/archive files with YYYYMMDD time stamp with optional hours & minutes.
If you wanted to assign a simple ${Original_Filename}.${sequence_no} then you could use awk to do something like this.
 
nextSequence=`ls -t1 ${archiveDir} | awk 'BEGIN { FS = "." } { if ($2 > max) {max=$2;} } END{ print max+1 }'`