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
end
every do |record|
if record.cols[8] =~ /^d/
puts %Q{ "#{record.cols[8]}" modified #{record.cols[6..7].join(" ")}}
@hits += 1
end
end
finish do
puts "#{@nr} files were processed"
puts %Q{#{@hits} files start with "d"}
end
'
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.