Hi all,
I have a script that has a part that needs to retrieve a list of IP addresses from a linux server which runs Netapp DFM.
when I execute the command and put is in a variable I get a each character in a new line, like a here-string.
Now, I need to only take the IP addresses out and put them all in an array.
Any idea how I can do that?
The variable output looks something like that:
PS C:\Users\XXX> $x
A
B
C
D
E
1
9
2
.
1
6
8
.
1
6
.
1
0
A
B
C
D
E
1
9
2
.
1
6
8
.
1
2
.
1
2
A
S
D
F
Thanks for the very prompt reply, it works great on the test $x example, I will try that also on my script.
I do have a FOR loop that does the work but I figured there must be a better and simpler way.
If anyone find that helpful here is my loop (created with a help of a friend)
Hi Dave,
I tried that within my script and unfortunately the regex has caught other numbers besides the IPs.
*one correction is that I get the output of the command like that:
ID Type Host Name Host Address ProductId Deleted
6721 Active/Active Controller xxx-xxx-xxx.com 192.168.111.12 2545002333 No
6738 Active/Active Controller yy-y-yyyy.com 192.168.111.13 24723423444 No
718 Active/Active Controller zzz-zzzz-zzzzz.com 192.168.111.14 1523223549 No
And the output from the regex is: (just and example I changed the real numbers)
That’s a mess. I would be trying to fix the upstream bit that is giving you each character on a single line, rather than trying to put it back together when you have multiple consecutive numeric fields. Fore example, is that 192.168.111.122545002333 meant to be an IP address that ends in .1, .12, or .122? There’s no way to know.
I understand the mess.
But the output of your parsing gives us something that is not that bad.
I mean the output pattern is always the same, I get the IP I want and some other numeric lines afterwards.
How can I select only the lines the start with ‘192.’ and drop all the rest?