我有许多 Markdown 文件,顶部有一个 YAML 元数据块:
---
title: title of work
author: author name
author-sort: name, author
published: N
date: XXXX-XX-XX
pub-number: XXXXX
embedded-title: false
---
**title**
a piece of indertimate
length that could be a few lines of many hundreds
---[author name](author link)
---found in [source](source link)
Run Code Online (Sandbox Code Playgroud)
我正在尝试找到一种提取元数据块的方法(这样我可以将其输入到yamllint
,但后来也可以输入其他内容)。awk 似乎是正确的工具,但是当我不理解 awk 时,我想出的最好的方法是:
awk '/^---$/ {printline = 1; print; next} /^---$/ {printline = 0} printline'
Run Code Online (Sandbox Code Playgroud)
这只是显示了整个文件,我尝试限制---
它们自己的行是行不通的(也许这里没有其他的)!