From: Robert Dober Date: 2007-06-30T20:36:09+09:00 Subject: Re: patten match On 6/19/07, geetha wrote: > Hi Good morning, > > I am having one text file. In this I need to remove all the new lines > and I need to match the keyword what I am giving. > > Please any one help me.... > > Thanks, > S.Sangeetha. Hmm removing the newlines can be done in different ways, I'll show you one below. However it is not clear to me what you mean by matching keywords, as a sample application I will replace the keyword by _keyword_, but maybe you shall ask again. def remove_nl_and_kw file_name, key_word="ruby" File.readlines(file_name). map{|line| line.chomp}. gsub(key_word, "_" << key_word << "_"). join end If you had the newlines removed because keywords might spwan lines you have to put join in front of gsub, but that might become a performance nightmare for larger files as you will be calling gsub on *huge* strings. HTH Robert -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck