ruby - Search and save a line containing a set of chars from an array -


i'm using readlines() read data 2 arrays, , need specific line.

problem:

i'm not sure string or array method use specific line containing '...blah' (my class' line/name of group.)

i prefer not save entire file content these 2 variables if possible. i'd rather "search" through file , save 2 specific lines need student_info , class_usernames.

student_info =  file.readlines ('/etc/passwd') class_usernames = file.readlines ('/etc/group') 

you use detect on array:

student_info    = file.readlines('/etc/passwd').detect { |s| s.include?('...blah') } class_usernames = file.readlines('/etc/group').detect { |s| s =~ /\.\.\.blah/ } 

and btw please not use whitespace between method name , parameter list.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -