You probably want something like: # this won't remove trailing newlines regex = /thing_to_match.*^/ file.each do |line| processed_line = line.gsub regex, '' print processed_line end ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Thu, Jul 14, 2011 at 20:37, Eddie Catflap <catflaporama / gmail.com> wrote: > Hi > > I have a regex as follows > > REG1=Regexp.new=('dodgydata') > > Basically, I need to read a file in line by line, and on each line > that's a match for my regex, remove everything from the point of the > regex to the end of that line. Is there a more efficient way to do it > than what I have at the moment? I have some HUGE files to process, and > many more regex matches to capture.. :-/ > > ARGF.each_line do [L] > > if L.index(REG1) > a=L.index(REG1) > b=L.length > L.slice!(a..b) > L << "\n" # Add a newline back to the end of the line > end > > print L > > end > > (As you can see I'm no ruby expert!). I'd like to be able to make this > more efficient, just doesn't seem a very Ruby way to do things.. All > help gratefully accepted! > > Regards > > Eddie > >