Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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