Skip to content

Instantly share code, notes, and snippets.

@oguz-ismail
Created January 31, 2021 09:40
Show Gist options
  • Save oguz-ismail/308f25eb586bc2ff5a769b9b1dc26310 to your computer and use it in GitHub Desktop.
Save oguz-ismail/308f25eb586bc2ff5a769b9b1dc26310 to your computer and use it in GitHub Desktop.
Splitting a file with a very long comma separated string of numbers into multiple files
# https://stackoverflow.com/q/65964916
# Usage: awk -v limit=17577 -f prog.awk file
BEGIN {
RS = ORS = ","
}
{
nread++
}
nread == 1 {
if (NR > 1) {
printf("\n") > file
}
close(file)
file = (FILENAME "_" ++nfile)
}
nread != 1 {
print prev > file
}
nread == limit {
printf("%s", $0) > file
nread = 0
next
}
{
prev = $0
}
END {
if (nread) {
printf("%s", prev) > file
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment