Skip to content

Instantly share code, notes, and snippets.

@bgamari
Created April 27, 2012 15:45
Show Gist options
  • Save bgamari/2510284 to your computer and use it in GitHub Desktop.
Save bgamari/2510284 to your computer and use it in GitHub Desktop.
Script to split file into chunks
#!/bin/bash
nchunks=$1
file=$2
nlines=$(wc -l $file)
let n=$nlines/$nchunks
for i in $(seq 1 $nchunks); do
let startline=$i*$n
tail -n +$startline $file | head -n $n > $file.$i
done;
@bgamari
Copy link
Author

bgamari commented Apr 27, 2012

!/bin/bash

nchunks=$1
file=$2
nlines=$(wc -l $file)
let n=$nlines/$nchunks
split -l $n $file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment