Created
July 3, 2022 15:44
-
-
Save bartv2/bb6f878131f996c196edf3eae99324de to your computer and use it in GitHub Desktop.
Split a kjot text export 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
/^###/ { header=1 } | |
/^# / && header { | |
if (/^# Page/) { | |
page=substr($0, 8) | |
} else { | |
if (page) { | |
page="" | |
dir=substr($0, 3) | |
} else { | |
dir=dir "/" substr($0, 3) | |
} | |
} | |
fn=dir "/" page | |
if (fn in v) { | |
v[fn]=v[fn] + (fn in v) | |
fn=v[fn] "/" fn | |
} else { | |
v[fn]=0 | |
} | |
gsub("/","_",fn) | |
} | |
!/^###/ && fn && page && !/^# Page/ { header=0; print > fn } | |
BEGIN { page="_" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment