From: Ken Bloom Date: 2009-12-24T10:08:37+09:00 Subject: Re: awk print $4 in ruby On Wed, 23 Dec 2009 13:12:11 +0900, Derek Smith wrote: > Hi All, > > I had played in Ruby a while and could not get this to work. > > df -m > Filesystem 1M-blocks Used Avail Capacity Mounted on > /dev/concat/v109-v112a 7931 2619 4677 36% / > > [root@vr /usr/local/vrep/OS_scripts]# df -k |awk '{print $4}' Avail > 4789776 > > dfstr = Array.new > dfstr << %x(df -m) > dfstr.each do |line| > puts line if line =~ /(\d+)%/ > end > > Since its one line, it of course prints it all. I then tried: > > dfstr.each do |line| > puts line.split[3] > end > > And it only prints "Avail" > > I then tried: > > puts dfstr.scan(/Avail.*/) > > and > > puts dfstr.split(/\d+/)[3] > > with NO success. > > Goal is to get certain data columns such as Used Avail Capacity. > > thank you! dfstr = %x(df -m) dfstr.each do |line| puts line.split[3] end Available 256227 1920 10 1920 -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/