Tuesday, August 23, 2011


I've created a gem called rawk.  It's a ruby DSL for command-line processing stream processing based on the classic AWK utility.   I wrote it because I like using awk, but I find it's lack of useful data structures a bit of a pain.  Rawk provides the same block-based processing, but using good old ruby.

Let's take an example.  I want to pretty-print the name and last modification date from a directory where the  filename starts with 'd'

$ ls -l /bin | rawk '
  start do 
    puts %q{Files n /bin starting with "d"}
    @hits = 0

  every do |record|
    if record.cols[8] =~ /^d/
      puts %Q{  "#{record.cols[8]}" modified #{record.cols[6..7].join(" ")}}
      @hits += 1

  finish do 
    puts "#{@nr} files were processed"
    puts %Q{#{@hits} files start with "d"}
Files n /bin starting with "d"
  "date" modified Dec 2010
  "dd" modified Dec 2010
  "df" modified Dec 2010
  "domainname" modified Jun 2010
38 files were processed
4 files start with "d"

You can install rak by running "gem install rawk"

See my github page for more information and detailed documentation on how to use rawk.