哎呀。我误解了问题!
无论如何,如果你碰巧想要统计脚注,并且使用的是带有 unix 命令行工具的环境(例如 linux / mac / windows 上的 unix 工具),那么你可以这样做:
cat FILENAME | tr '\\' '\n' | awk '/^f /{footnote++;}/^x /{xref++;}/^c /{print chapter, footnote, xref ; chapter=0+$2; footnote=0;xref=0;}END{print chapter, footnote, xref; }'
它的作用是确保每个新的 SFM 都从新的一行开始,然后统计脚注、交叉引用,当出现章节号(或结尾)时打印计数。我不会说 Python,而且注释是在 XML 文件中,用 awk 解码起来相当麻烦。
Bother. I misunderstood the question!
Anyway, if you happened to want to count footnotes, and are using something with unix command-line tools available (e.g. linux / mac / unix-tools for windows), then you can do something like this:
cat FILENAME | tr '\\' '\n' | awk '/^f /{footnote++;}/^x /{xref++;}/^c /{print chapter, footnote, xref ; chapter=0+$2; footnote=0;xref=0;}END{print chapter, footnote, xref; }'
What it does is make sure that every new SFM starts a new line, and then counts the footnotes, xrefs and when there’s a chapter number (or the end) it prints the counts. I don’t speak python though, and notes are in an XML file which is quite a bit too nasty to decode with awk.
机器翻译自 English