From: Reid Thompson Date: 2007-06-15T23:18:50+09:00 Subject: Re: Create text files... On Fri, 2007-06-15 at 16:53 +0900, Tom Bombadil wrote: > 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. > > ====================================================== not ruby, but... $ csplit -f cve -z -n4 -k test.txt '/===================/' '{99999}' $ ls -rlt cve* -rw-r--r-- 1 rthompso staff 56 Jun 15 08:14 cve0003 -rw-r--r-- 1 rthompso staff 511 Jun 15 08:14 cve0002 -rw-r--r-- 1 rthompso staff 416 Jun 15 08:14 cve0001 -rw-r--r-- 1 rthompso staff 9 Jun 15 08:14 cve0000 $for file in `ls cve*` do echo $file echo "begin file output" cat $file echo "end file output" echo "" done cve0000 begin file output Test.txt end file output cve0001 begin file output ====================================================== 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. end file output cve0002 begin file output ====================================================== 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. end file output cve0003 begin file output ====================================================== end file output