Skip to content

Instantly share code, notes, and snippets.

@bartv2
Created July 3, 2022 15:44
Show Gist options
  • Save bartv2/bb6f878131f996c196edf3eae99324de to your computer and use it in GitHub Desktop.
Save bartv2/bb6f878131f996c196edf3eae99324de to your computer and use it in GitHub Desktop.
Split a kjot text export into multiple files
/^###/ { 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