Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Forked from maesa/splitter.sh
Created September 24, 2018 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambdamusic/d4319e6e09e227fe8f9a833a7797b79c to your computer and use it in GitHub Desktop.
Save lambdamusic/d4319e6e09e227fe8f9a833a7797b79c to your computer and use it in GitHub Desktop.
Bash script for splitting large CSV files while keeping the header into 100 lines a piece using Split. Outputs as Part1, Part2, ... while keeping its Header
#!/bin/bash
FILENAME=filename_here.csv
HDR=$(head -1 $FILENAME)
split -l 100 $FILENAME xyz
n=1
for f in xyz*
do
if [ $n -gt 1 ]; then
echo $HDR > Part${n}.csv
fi
cat $f >> Part${n}.csv
rm $f
((n++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment