Skip to content

Instantly share code, notes, and snippets.

@elias19r
Last active August 16, 2022 21:18
Show Gist options
  • Save elias19r/f51facc4ee85c9c5a5548ac7f676a1e0 to your computer and use it in GitHub Desktop.
Save elias19r/f51facc4ee85c9c5a5548ac7f676a1e0 to your computer and use it in GitHub Desktop.
#!/bin/bash
file_path='./your-file.csv'
n_lines=5000
# tail -n +2 $file_path: Prints the whole file starting from the second line (skip header)
# split -l $n_lines - part_: Split the content into small files of $n_lines each named "part_*"
tail -n +2 "${file_path}" | split -l "${n_lines}" - part_
# For each part_*
i=1
for part_x in part_*
do
# Add the header to a temporary file
head -n 1 "${file_path}" > tmp_file
# Append part_x's content to the temporary file
cat "${part_x}" >> tmp_file
# Rename the temporary file and deletes part_x
mv tmp_file "${file_path}.${i}"
rm "${part_x}"
i=$((i+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment