On Tue, Jul 17, 2012 at 3:20 AM, Jon R. <[email protected]> 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/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en