From: jake kaiden Date: 2011-07-28T02:36:30+09:00 Subject: Re: if condition for pattern matching kotin 76 wrote in post #1013393: > Hi , > > i applying same above logic for below program > > 1 > 2 #!/usr/bin/env ruby > 3 > 5 dev2 = File.readlines("dev_string2.txt") > 8 > 9 > 10 for i in dev2 > 11 devstring=i.match(/\/dev\/[\w]+/) > 12 puts devstring > 14 if devstring =~ %r{/dev/} then > 15 puts "pass" > 16 end > 17 end hi Kotin - have a look here: http://www.ruby-doc.org/core/classes/File.html, and here: http://www.ruby-doc.org/core/classes/IO.html#M000896, for more info on ruby's File methods... i would use File.open with a block for this operation - something like this: File.open("dev_string2.txt", "r"){|file| file.each{|line| if line =~ %r{/dev/} puts "pass: #{line}" end } } note that running this the second line of your file does not pass, as it ends in "/dev", and not "/dev/". i'm not sure if this is your intended result. if you want the second line to pass as well, you could just change your regex to %r{/dev}. - j -- Posted via http://www.ruby-forum.com/.