1998-01-16 15:13:05 +03:00
|
|
|
#! ./ruby
|
|
|
|
# split into multi part
|
|
|
|
# usage: mpart.rb [-nnn] file..
|
|
|
|
|
2022-11-25 08:22:37 +03:00
|
|
|
class MPart < File
|
|
|
|
def self.new(basename, extname, part, parts)
|
|
|
|
super(sprintf("%s.%s%02d", basename, extname, part), "w").
|
|
|
|
begin_mpart(basename, part, parts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def begin_mpart(basename, part, parts)
|
|
|
|
printf("%s part%02d/%02d\n", basename, part, parts)
|
|
|
|
write("BEGIN--cut here--cut here\n")
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
write("END--cut here--cut here\n")
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
lines = 1000
|
|
|
|
|
|
|
|
if (ARGV[0] =~ /^-(\d+)$/ )
|
2022-11-25 08:22:37 +03:00
|
|
|
lines = $1.to_i
|
|
|
|
ARGV.shift
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
basename = ARGV[0]
|
|
|
|
extname = "part"
|
|
|
|
|
|
|
|
part = 1
|
|
|
|
line = 0
|
2022-11-25 08:22:37 +03:00
|
|
|
ofp = nil
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
fline = 0
|
2022-11-25 08:22:37 +03:00
|
|
|
File.foreach(basename) {fline += 1}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
parts = fline / lines + 1
|
|
|
|
|
2022-11-25 08:22:37 +03:00
|
|
|
File.foreach(basename) do |i|
|
1998-01-16 15:13:05 +03:00
|
|
|
if line == 0
|
2022-11-25 08:22:37 +03:00
|
|
|
ofp = MPart.new(basename, extname, part, parts)
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
ofp.write(i)
|
2022-11-25 08:22:37 +03:00
|
|
|
line += 1
|
|
|
|
if line >= lines
|
1998-01-16 15:13:05 +03:00
|
|
|
ofp.close
|
2022-11-25 08:22:37 +03:00
|
|
|
part += 1
|
1998-01-16 15:13:05 +03:00
|
|
|
line = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ofp.close
|