From: Edwin Fine Date: 2007-02-16T14:18:45+09:00 Subject: Re: Processing a text file barjunk wrote: > I have a radius users text file that has entries like: > > # username - Thu Feb 15 08:59:03 AKST 2007 > davidh Calling-Station-Id != "00-1A-02-3E-93-28", Auth-Type := Reject > davidh User-Password == "secretpass" > # ... I don't know how big the file is, but if you can read it all into a string (e.g. str = File.read("the_file") ), you could use something like this: def zap_unwanted_lines(str, user) re = %r[ ^\#\s+username\s+-\s+\w{3}\s\w{3}\s\d{2}\s\d{2}:\d{2}:\d{2}\s\w+\s\d{4}\n #{user}\s+Calling-Station-Id[^\n]+\n #{user}\s+User-Password[^\n]+\n \#\s*\n ]x str.gsub re, '' end TEXT = %q{ # username - Thu Feb 15 08:59:03 AKST 2007 davidh Calling-Station-Id != "00-1A-02-3E-93-28", Auth-Type := Reject davidh User-Password == "secretpass" # } dummy = "This is some dummy text\n" * 5 fake_radius_data = dummy + TEXT + dummy + TEXT + dummy puts "--- Before zapping ---" puts fake_radius_data puts "--- After zapping ---" puts zap_unwanted_lines(fake_radius_data, "davidh") -- Posted via http://www.ruby-forum.com/.