From: Shin Nishiyama Date: 2002-10-18T12:20:28+09:00 Subject: Re: one liner? --- need help splitingi a file Hello, >I need to split a file > > Part A > .... > .... > > Part B > .... > .... > >to files A, B, ... > >Would somebody show me how to do it in Ruby? I have used Perl before >for data parsing, but have forgotten most of the usage. I am interested >in Ruby, wishing it's easier to learn and maintain than Perl. > >Thanks. > >Dong How about this, fname = nil File.open("orig") {|f| while(l = f.gets) if l =~ /^Part ([A-Z])/ file.close if fname fname = $1 file = File.open(fname,"w") end file.puts l if fname end } file.close if fname - Shin Nishiyama -------- Department of Materials Technology, Faculty of Engineering, Chiba-University ------------------------------------------------------