Capture information with a split and maybe a match?

A

anon1m0us

Hi;
Here is my line of code that I need help in:
result_of_na_citrix=`net group na-citrix /dom`.split(" ")
This gets all the users in in it's own index split on a space.
However, there is a bunch of garbage (stuff that I do not need to
capture) before the names of the users are listed. Here is an example

The request will be processed at a domain controller for domain
abc.com.

Group name NA-CITRIX
Comment Owner:John Doe

Members

-------------------------------------------------------------------------------
The list of users begins here.


I need to get the list of users ONLY. Basically, to capture info AFTER
the dashes -----------. I did a 20.times do, but each group has a
different information. The ONLY consistent thing is the list of users
that start AFTER the dashes,
 
H

Harry

However, there is a bunch of garbage (stuff that I do not need to
capture) before the names of the users are listed. Here is an example

The request will be processed at a domain controller for domain
abc.com.

Group name NA-CITRIX
Comment Owner:John Doe

Members

-------------------------------------------------------------------------------
The list of users begins here.


I need to get the list of users ONLY. Basically, to capture info AFTER
the dashes -----------. I did a 20.times do, but each group has a
different information. The ONLY consistent thing is the list of users
that start AFTER the dashes,

If I understand your question, something like this should help.


str = "Group name NA-CITRIX\nComment Owner:John Doe\nMembers\n" +
"-----------------------------------------------------" +
"--------------------------\nThe list of users begins here."

str =~ /.*?-{3,}.*?(\w.*)/m
puts $1



Look into regular expressions and adjust as necessary.
http://www.rubycentral.com/book/tut_stdtypes.html#S4

Harry
 
A

Andrew Johnson

anon1m0us said:
I need to get the list of users ONLY. Basically, to capture info AFTER
the dashes -----------. I did a 20.times do, but each group has a
different information. The ONLY consistent thing is the list of users
that start AFTER the dashes,

Use the String#[] method with a regex to just return the portion
following
the dashes, and split that:

result_of_na_citrix = `net group na-citrix
/dom`[/-+\n(.*)/m,1].split(" ")

cheers,
andrew
 
C

ChrisH

anon1m0us said:
I need to get the list of users ONLY. Basically, to capture info AFTER
the dashes -----------. I did a 20.times do, but each group has a
different information. The ONLY consistent thing is the list of users
that start AFTER the dashes,

Use the String#[] method with a regex to just return the portion
following
the dashes, and split that:

result_of_na_citrix = `net group na-citrix
/dom`[/-+\n(.*)/m,1].split(" ")

cheers,
andrew

I'd suggest:
separator =
"-------------------------------------------------------------------------------
\n"
junk,users = `net group na-citrix /dom`.split(separator)
user_array = users.split(' ')

YMMV

Cheers
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,239
Messages
2,571,200
Members
47,840
Latest member
Tiffany471

Latest Threads

Top