I've read an input file and extracted each column in to individual arrays like below.
id = ["id\a_po87y", "id\ruio66", "id\rzd766", "id\ruio66", etc..]
store = ["Jack", "John_Marsha", "123_Smart_option", "John_Marsha", etc...]
group = ["leader", "leader_1", "fresher", "automation_dev", etc...]
id_details.txt (input file)
id\a_po87y Jack leader
id\ruio66 John_Marsha leader_1
id\rzd766 123_Smart_option fresher
id\ruio66 John_Marsha automation_dev
....
etc
How should I iterate the arrays in a nested fashion in such a way that, the first element of the array - 'id'(id\a_po87y) should be checked for its preence in the file Jack_details.txt (1st element of the store array) and should be deleted from the row name - leader (again 1st array element of group array)
Likewise, id\ruio66 should be checked for its availabilty in the 2dn file - John_Marsha in the row id - leader_1 and if present, remove it.
so on..
id[0]--> store[0]-->group[0]
id[1]--> store[1]-->group[1]
and so on
My code, but the values are skipped in the array elements
file_dir = 'E:/ruby_work'
file = File.open("E:/ruby_work/id_details.txt", "r")
contents = file.each_line.map { |line| line.split("\t") }.transpose
id, file_name, group = contents
id.each do |ids|
puts "For ID: #{ids}"
file_name.each do |name|
value = File.open("#{file_dir}/#{name}_details.txt")
text = File.read(value)
#puts text
text.each_line do |el|
group.each do |gr|
if el.match(/#{gr}/) then
print "group row #{gr}\n"
print "Its matching\n"
replace = text.gsub( /#{Regexp.escape(ids)}\,\s/, '').gsub( /#{Regexp.escape(ids)}/, '' ).gsub /,\s*$/, ''
else print "Not\n"
print "group row #{gr}\n"
end
group.shift
end
end
file_name.shift
end
end
id.shift
What i'm doing wrong?
Jack_details.txt
Joined on Feb 7, 2016
Created by: Solomon (ruio66)
[groups]
leader_1 = id\rty67, id\mztrt, id\ruio66, ncr\025kc, id\a_po87y
automation = id\bzo0l4, ccr\poxz7j
automation_dev = id\ruio66
John_Marsha_details.txt
Joined on Jan 7, 2016
Created by: Jack Rondon
[groups]
leader_1 = id\sop0r2, id\34_dev, id\mz4d5, id\ruio66
fresher = id\kzpo98, id\gz8sl7, id\cp0jxr, id\fzxlol,
automation_dev = id\ruio66
Output
For ID: id\a_po87y
Not
group row leader
Not
group row leader_1
For ID: id\ruio66