Skip to content

Instantly share code, notes, and snippets.

@mkrasowski
Created May 27, 2013 13:03
Show Gist options
  • Save mkrasowski/5656959 to your computer and use it in GitHub Desktop.
Save mkrasowski/5656959 to your computer and use it in GitHub Desktop.
Split file into parts containing at most given number of lines.
#!/bin/bash
file=$1
lines=$2
sumLines=$(wc -l $file | cut -f1 -d' ')
processed=0
part=1
while [ $processed -lt $sumLines ]
do
startLine=$[processed+1]
endLine=$[processed+lines]
processed=$endLine
if [ $endLine -gt $sumLines ]; then
endLine="\$"
fi
sed -n -e "$startLine,$endLine p" $file > $file.p${part}
part=$[part+1]
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment