Skip to content

Instantly share code, notes, and snippets.

@codernik
Created February 11, 2021 18:35
Show Gist options
  • Save codernik/846b5a507735b851c06a63c3b6b088eb to your computer and use it in GitHub Desktop.
Save codernik/846b5a507735b851c06a63c3b6b088eb to your computer and use it in GitHub Desktop.
Shell script for spliting csv file into multiple parts.
#!/bin/bash
FILENAME=main.csv
HDR=$(head -1 $FILENAME)
split -l 1000 $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