Skip to content

Instantly share code, notes, and snippets.

@musaprg
Created January 22, 2017 16:34
Show Gist options
  • Save musaprg/35a3387d876a424ecb72c66544da5272 to your computer and use it in GitHub Desktop.
Save musaprg/35a3387d876a424ecb72c66544da5272 to your computer and use it in GitHub Desktop.
Split num with any digit you want.
if ARGV.count < 1
puts "Usage: ruby split.rb hoge.txt <split_num>"
exit
end
fname = ARGV[0]
n = ARGV[1]
fn = fname.split(".")
File.open(fname, 'r') do |f|
File.open(fn[0] + '_r.txt', 'w') do |rf|
txt = f.read
a = txt.scan(/.{1,#{n}}/)
a.each { |s| rf.puts(s)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment