Skip to content

Instantly share code, notes, and snippets.

@jishanshaikh4
Created May 26, 2022 13:54
Show Gist options
  • Save jishanshaikh4/c43677d42aecf23b52591de6ec4294a0 to your computer and use it in GitHub Desktop.
Save jishanshaikh4/c43677d42aecf23b52591de6ec4294a0 to your computer and use it in GitHub Desktop.
Split a 12 MB text file into 12 separate text files with index (awk)
awk '{
a[NR] = $0
}
END {
for (i = 1; i in a; ++i) {
x = (i * 12 - 1) / NR + 1
sub(/\..*$/, "", x)
print a[i] > "file" x ".txt"
}
}' file.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment