Skip to content

Instantly share code, notes, and snippets.

@v-sukt
Created July 31, 2019 12:43
Show Gist options
  • Save v-sukt/c895524b7793932fa8556a6e5f53b720 to your computer and use it in GitHub Desktop.
Save v-sukt/c895524b7793932fa8556a6e5f53b720 to your computer and use it in GitHub Desktop.
Split file on basis of lines - like big csv file
#!/usr/bin/env bash
#cp ${1} ${1}-$(date +%s).bkp
lines=2 # indicate the number of lines each split should have
last_line=1
count=0
end=$(wc -l <${1})
while [[ ${last_line} -lt ${end} ]]; do
tail -n +${last_line} $1 | head -n ${lines} > ${1}_split_${count}
last_line=$((last_line+lines))
count=$((count+1))
done
tail -n +${last_line} $1 > ${1}_split_${count}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment