From: Bertram Scharpf Date: 2009-12-08T00:33:22+09:00 Subject: Re: awk to ruby 1.9 Hi, Am Samstag, 05. Dez 2009, 05:09:35 +0900 schrieb Panagiotis Atmatzidis: > ------------ > > File.foreach(filename) do |line| > puts "#{line}" if line =~ /Ban/ > end > > ipadds.get_ips("fail2ban.log") > -------------- > > The output though parses lines the following: > > 2009-11-19 00:31:29,928 fail2ban.actions: WARNING [ssh-ipfw] Ban 203.169.139.171 > > I would like to use the output from the cli: "$ grep Ban fail2ban.log|awk -F "Ban" '{print $2}'" The correct translation of `-F Ban "{print $2}"' would be ary = line.split /Ban/ puts ary[ 2] I would prefer something like if line =~ /Ban\s+/ then puts $'.split.first end You can play around that for the rest of the day: ary = line.split while ary.any? do if ary.shift == "Ban" then puts ary.first break end end I don't think it's worth here the effort of IP address parsing but thats surely a matter of taste. Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany * Discover String#notempty? at .