From: Aleksey V Zapparov Date: 2012-07-04T08:54:58+09:00 Subject: Re: Newbie needs help with parsing a file --Sig_/4uWMSeRkTnv8C7Z4Lrv1EUM Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Wed, 4 Jul 2012 07:52:16 +0900 "Jon R." wrote: > I have a file with a long string in the following format: >=20 > /vol/dept115345K111455K/vol/home1156668K507768K...ad finitum. >=20 > How do I iterate through the string comparing dividing the second > number by the first number and only print the output if the number is > 90% or more? Basically the first number is total space and the > second number is used space. If the comparison is 90% or more, then > print the vol name /vol/dept(etc.) along with the %. If the > comparison is less than 90% then don't print it at all. In other > words using the two above I would get >=20 > /vol/dept 96.6% str =3D "/vol/dept115345K111455K/vol/home1156668K507768K" str[1..-1].split("/").inject([]) do |arr, str| next arr if "vol" =3D=3D str next arr if 2 > arr.push(str).count dept, home =3D arr puts "#{dept} VS #{home}" [] end I guess the idea is clear to build final solution :)) --=20 Sincerely yours, Aleksey V. Zapparov A.K.A. ixti FSF Member #7118 Mobile Phone: +34 677 990 688 Homepage: http://www.ixti.net JID: zapparov@jabber.ru *Origin: Happy Hacking! --Sig_/4uWMSeRkTnv8C7Z4Lrv1EUM Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iQEcBAEBAgAGBQJP84ZKAAoJEGRO9nGLm9Y8TLwIAIs+kmeKbiqH6vwdUQ1UbQdb HdkfEcXMC8WPlHHkkYtDZd+sAKZHOmXAcU5afnNItjoYFsT4V5Cg3eUU2oHK9O7M FrMfVfY+Zxtk/Ic+Qjnvn9Ubta6PSmuxsISVHnKiz8BCsmMeW9Wow33ww5UMrYf6 WJCtV54ENdPFSYktjCWaWhzoOx5bWH9u20v/yCVXeubxXFtMYfx0Wa5j1J7Qowjr Wmyb//wN5QXzZN1lzhu8ZvEWHOPEFMlhToZGgevxdra1WwGY3zvFd7kz6YYv173u 3TGSsqVqPhQigi4SAgYdYIz+YVxiCwIElO/skblMjZJi1b5Z0WlyKULhLJhbN94= =IDUM -----END PGP SIGNATURE----- --Sig_/4uWMSeRkTnv8C7Z4Lrv1EUM--