b.k.

Unix Commands I Love

I’ve been spending more time lately increasing my knowledge of unix commands in order to make my daily log parsings, etc easier. I’ve found that I have a lot of commands that I use out of habit and they get things done, but not necessarily in the best way. So I thought I’d write about a few of my favorite new commands.

watch

The watch command is great for monitoring something for a change, or just to keep an open status.

You can do something simple just to keep a terminal session active

watch -n 60 date

or something more complex like generating a small report from log output

watch -n 30 'echo "SUCCESS"; grep -ic "success" results.log; echo "SKIPPED"; grep -icv "success" results.log; echo "TOTAL"; wc -l results.log;

this will generate a nice little report like:

SUCCESS
13886
SKIPPED
114
TOTAL
14000 results.log

the -n [sec] argument defines how frequently to update the data. At that interval the screen will refresh and the updated info displayed.

awk

I have several awk one liners that I use almost daily

  • Yank a specific record from an LDIF
    gawk 'BEGIN {IGNORECASE=1; RS="\n\n"} /cn: Brian Kohles/ {print ; print "";} example.ldif
    
  • Count occurences column 1 ($1) in a file
    awk '{count[$1]++} END {for(j in count) print j,"\t" count[j]}'
    
  • Split a file into multiple 1000 line files
    awk 'NR%1000 == 1 {file = "outputfile" i++} {print > file}' file.txt
    

Permanent Holiday - Mike Love

I’m not usually one to listen to Raggae, but I can’t get this song out of my head.

I’m sure this guy won’t be happy that I make the comparison but I’d say he is the Ed Sheran of Raggae.

The way he builds up the middle of the song by looping single syllable sections of the lyrics is amazing.