From: Panagiotis Atmatzidis Date: 2009-12-08T01:35:25+09:00 Subject: Re: awk to ruby 1.9 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, On 07 Δεκ 2009, at 5:33 μ.μ., Bertram Scharpf wrote: > 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 First, thanks for the code. The parsing that I use was ready actually and works quite nice. I'm not able to write regexp at that level yet. That's why I used it. > > > -- > Bertram Scharpf > Stuttgart, Deutschland/Germany > * > Discover String#notempty? at . > Panagiotis (atmosx) Atmatzidis email: atma@convalesco.org URL: http://www.convalesco.org GnuPG ID: 0xFC4E8BB4 gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xFC4E8BB4 - -- The wise man said: "Never argue with an idiot. They bring you down to their level and beat you with experience." -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.12 (Darwin) iEYEARECAAYFAksdLsoACgkQrghUb/xOi7QRCACdFTT8hkstbPlj62mTTQyqkOJ0 DqQAn1w/mEOiVDPk1lgDHCCMVk15m/Ew =rCzl -----END PGP SIGNATURE-----