Created
January 31, 2021 09:40
-
-
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
This file contains hidden or 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
# 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