0

I want to read data from a text file and retrieve just the ip_addresses contained in the file.

The file contains data as:

[#<host:192.168.2.135>, #<host:175.41.142.49>, #<host:20:aa:4b:9b:eb:8c>, #<host:20:7c:8f:10:38:a0>, #<host:192.168.2.1>, #<host:239.255.255.250>]

From these data, i just want the host addresses like 192.168.2.135 and so on and store them in an array.Could somebody please help me with this? Thanks in advance.

1 Answer 1

2
open(path_to_file, &:read).scan(/#<host:(.+?)>/).flatten
Sign up to request clarification or add additional context in comments.

1 Comment

Now, if my file contains data like [#<sum 192.168.2.135 2411669>] and out of this, I want only the number 2411669, how should I do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.