On Tue, Jul 17, 2012 at 3:20 AM, Jon R. <lists / ruby-forum.com> wrote:
> I have a file of the form
>
> server.corp.abc.com:/vol/test/xyz
> server2.corp.def.com:/vol/stage/123
> server3.corp.xyz.net:/vol/prod/abc
>
> and etc.
>
> How do I return a list of only the server names?  In other words
> everything up to but not including the ":".  I can read the file in and
> can even split it at the ":" but can't seem to figure out how to only
> get server.corp.abc.com
> server2.corp.def.com
> server3.corp.xyz.net

I like

$ cat x
server.corp.abc.com:/vol/test/xyz
server2.corp.def.com:/vol/stage/123
server3.corp.xyz.net:/vol/prod/abc


irb(main):001:0> s=File.foreach("x").map {|l| l[/^\s*([^:\s]+)/, 1]}
=> ["server.corp.abc.com", "server2.corp.def.com", "server3.corp.xyz.net"]

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/