From: Gennady Bystritsky Date: 2010-04-13T23:39:25+09:00 Subject: Re: how to delete the first two characters of each row? On Apr 13, 2010, at 4:17 AM, Pen Ttt wrote: > how to delete the first two characters of each row? > i want to delete the first two characters of each row in file > /home/pt/test/mtp.txt > > > io=open("/home/pt/test/mtp.txt","r") > io1=open("/home/pt/test/mtpback.txt","w") > while line=io.gets > ioput=line.delete("/^..../") As Brian has mentioned, String#delete in your code is instructed to remove the actual string starting with character '/', not a regular expression, as you might have meant. Also, most likely you want to exclude end-of-lines from counting. Another problem is that your files remain open, so you need to close them at some point. I think you need something like this: File.open("/home/pt/test/mtpback.txt", "w") { |output| File.open("/home/pt/test/mtp.txt", "r") { |input| input.each { |line| output.puts line.chomp[2..-1].to_s } } } Gennady.