home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rbemx144.zip / ruby-1.4.4 / sample / mpart.rb < prev    next >
Text File  |  1999-12-21  |  755b  |  45 lines

  1. #! ./ruby
  2. # split into multi part
  3. # usage: mpart.rb [-nnn] file..
  4.  
  5. lines = 1000
  6.  
  7. if (ARGV[0] =~ /^-(\d+)$/ )
  8.   lines = $1.to_i;
  9.   ARGV.shift;
  10. end
  11.  
  12. basename = ARGV[0]
  13. extname = "part"
  14.  
  15. part = 1
  16. line = 0
  17.  
  18. fline = 0
  19. for i in ifp = open(basename)
  20.   fline = fline + 1
  21. end
  22. ifp.close
  23.  
  24. parts = fline / lines + 1
  25.  
  26. for i in ifp = open(basename)
  27.   if line == 0
  28.     ofp = open(sprintf("%s.%s%02d", basename, extname, part), "w")
  29.     printf(ofp, "%s part%02d/%02d\n", basename, part, parts)
  30.     ofp.write("BEGIN--cut here--cut here\n")
  31.   end
  32.   ofp.write(i)
  33.   line = line + 1
  34.   if line >= lines and !ifp.eof?
  35.     ofp.write("END--cut here--cut here\n")
  36.     ofp.close
  37.     part = part + 1
  38.     line = 0
  39.   end
  40. end
  41. ofp.write("END--cut here--cut here\n")
  42. ofp.close
  43.  
  44. ifp.close
  45.