Is the highlighted section allowed in ruby ?
......
......
text = File.read(file_name)
....
....
row = text.grep(/#{Regexp.escape(line)}/g) { |log| log.split.first }
puts "From: #{row}"
.......
......
('line' is the variable substitution holds string values like -rr0\hu)
I know I can use the below method to read and search a pattern in files but I have to read multiple files and check if string is present (may be in multiple lines) and get the first word of matched string's line(s).
File.open('abc.txt').grep(/rr0\hu/) { |line| line.split.first }
How can I do this in Ruby?