From: Axel Etzold Date: 2007-06-15T18:04:17+09:00 Subject: Re: Create text files... Dear Tom, you could do the following: all_text=IO.readlines("test.txt").to_s.split(/\=+/) name_regexp=/Name: ([^\n]+)/ all_text.each{|entry_between_equal_signs| file_name=name_regexp.match(entry_between_equal_signs) if file_name!=nil and File.exists?(file_name[1]+'.txt')==false f=File.new(file_name[1]+'.txt','w') f.puts entry_between_equal_signs f.close end } Best regards, Axel -------- Original-Nachricht -------- Datum: Fri, 15 Jun 2007 16:53:53 +0900 Von: "Tom Bombadil" An: ruby-talk@ruby-lang.org Betreff: Create text files... > Hi, > > I do have a text file as shown below. I'd now like to use Ruby to create > separate text files for the content between "======". To do so I have: > > # Open, read from a text file, and pass to block f1 > File.open('test.txt', 'r') do |f1| > while line = f1.gets > puts line > end > end > > # Create a new file and write to it > File.open('cve.txt', 'w+') do |f2| > if f2 =~ /Name/ > puts line > end > end > > Though cve.txt is empty and I just have one cve.txt. Pls advise. I > appreciate. > > > Test.txt > ====================================================== > Name: CVE-1999-0005 > Status: Entry > Reference: CERT:CA-98.09.imapd > Reference: SUN:00177 > Reference: URL: > http://sunsolve.sun.com/pub-cgi/retrieve.pl?doctype=coll&doc=secbull/177 > Reference: BID:130 > Reference: URL:http://www.securityfocus.com/bid/130 > Reference: XF:imap-authenticate-bo > > Arbitrary command execution via IMAP buffer overflow in authenticate > command. > > ====================================================== > Name: CVE-1999-0006 > Status: Entry > Reference: CERT:CA-98.08.qpopper_vul > Reference: SGI:19980801-01-I > Reference: URL: > ftp://patches.sgi.com/support/free/security/advisories/19980801-01-I > Reference: AUSCERT:AA-98.01 > Reference: XF:qpopper-pass-overflow > Reference: BID:133 > Reference: URL:http://www.securityfocus.com/bid/133 > > Buffer overflow in POP servers based on BSD/Qualcomm's qpopper allows > remote attackers to gain root access using a long PASS command. > > ====================================================== -- GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS. Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail