Skip to content

Instantly share code, notes, and snippets.

@vtmx
Last active October 3, 2023 02:38
Show Gist options
  • Select an option

  • Save vtmx/4603151226ee55b004454ceb9ee12740 to your computer and use it in GitHub Desktop.

Select an option

Save vtmx/4603151226ee55b004454ceb9ee12740 to your computer and use it in GitHub Desktop.
gian-divider
#!/usr/bin/env bash
# Nome do arquivo a ser dividido
file="./arq.csv"
# Recebe total de linhas
file_lines=$(wc -l < $file)
# Divisor
divider=10
# Linha atual
current_line=1
# Nome do arquivo atual
current_file="file$divider.csv"
# Cria primeiro arquivo
> $current_file
# Loop pelas linhas
while read line; do
# Adiciona a linha no arquivo atual
echo "$line" >> "$current_file"
# Se for divisível por 10
if [[ $((current_line % divider)) -eq 0 && $current_line -ne $file_lines ]]; then
# Atualiza valor do arquivo atual
current_file="file$((current_line + $divider)).csv"
# Cria arquivo com novo valor
> "$current_file"
fi
# Incrementa valor da linha atual
((current_line++))
done < $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment