DEFAULT_NUM = 10
def main( argv)
unless argv.length < = 2
print "Usage: ruby #{__FILE__} file-name [num]"
exit 1
end
file_name = argv[ 0 ]
num = if argv[ 1 ] .nil ?
DEFAULT_NUM
else
argv[ 1 ] .to_i
end
unless num > = 1
print "Invalid number"
exit 1
end
write_file_by_n file_name, num
end
def write_file_by_n( input_file_name, num)
File .open ( input_file_name, 'r' ) .each_line .each_slice ( num) .with_index do
| lines, index|
output_file_name = format "%s-%d" , input_file_name, index + 1
File .open ( output_file_name, 'w' ) do | out_file|
lines.each do | line|
out_file.puts line
end
end
end
end
if __FILE__ == $0
main ARGV
end
REVGQVVMVF9OVU0gPSAxMAoKCmRlZiBtYWluKGFyZ3YpCiAgICB1bmxlc3MgYXJndi5sZW5ndGggPD0gMgogICAgICAgIHByaW50ICJVc2FnZTogcnVieSAje19fRklMRV9ffSBmaWxlLW5hbWUgW251bV0iCiAgICAgICAgZXhpdCAxCiAgICBlbmQKCiAgICBmaWxlX25hbWUgPSBhcmd2WzBdCiAgICBudW0gICAgICAgPSBpZiBhcmd2WzFdLm5pbD8KICAgICAgICAgICAgICAgICAgICBERUZBVUxUX05VTQogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgIGFyZ3ZbMV0udG9faQogICAgICAgICAgICAgICAgZW5kCgogICAgdW5sZXNzIG51bSA+PSAxCiAgICAgICAgcHJpbnQgIkludmFsaWQgbnVtYmVyIgogICAgICAgIGV4aXQgMQogICAgZW5kCgogICAgd3JpdGVfZmlsZV9ieV9uIGZpbGVfbmFtZSwgbnVtCmVuZAoKCmRlZiB3cml0ZV9maWxlX2J5X24oaW5wdXRfZmlsZV9uYW1lLCBudW0pCiAgICBGaWxlLm9wZW4oaW5wdXRfZmlsZV9uYW1lLCAncicpLmVhY2hfbGluZS5lYWNoX3NsaWNlKG51bSkud2l0aF9pbmRleCBkbwogICAgICAgIHxsaW5lcywgaW5kZXh8CgogICAgICAgIG91dHB1dF9maWxlX25hbWUgPSBmb3JtYXQgIiVzLSVkIiwgaW5wdXRfZmlsZV9uYW1lLCBpbmRleCArIDEKICAgICAgICBGaWxlLm9wZW4ob3V0cHV0X2ZpbGVfbmFtZSwgJ3cnKSBkbyB8b3V0X2ZpbGV8CiAgICAgICAgICAgIGxpbmVzLmVhY2ggZG8gfGxpbmV8CiAgICAgICAgICAgICAgICBvdXRfZmlsZS5wdXRzIGxpbmUKICAgICAgICAgICAgZW5kCiAgICAgICAgZW5kCiAgICBlbmQKZW5kCgoKaWYgX19GSUxFX18gPT0gJDAKICAgIG1haW4gQVJHVgplbmQ=