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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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