In a script like this for splitting a large file by string:
awk '/MYSTRING/ {n++}{print >"out_" n ".txt" }' LARGEFILE
This produces out_1.txt, out_2.txt, etc.
How can I get letter prefixes as produced by split (out_aa.txt, out_ab.txt, out_ac.txt, ...)?
Thanks
Its not very straight forward so allow me to use some modulo arithmetic here like this:
awk '/MYSTRING/ {n++} {p=97+int(n/26); q=(n%26)+97; s=sprintf("out_%c%c.txt", p, q); print > s}' LARGEFILE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With