下面是我的输入文件:
---
{
"date":"2015-09-24",
"title":"Getting Started with Git",
"template":"post",
"thumbnail":"content/thumbnails/test.jpeg",
"slug":"getting-started-with-git",
"categories":[ "cat1", "Focus", "Mustang" ],
"tags":[ "Fiesta", "Focus", "Mustang" ]
}
---
#Hello
---
This is sample
---
```
var x=1;
entry.forEach(function(item){
x=x++;
})
```
Run Code Online (Sandbox Code Playgroud)
我在输出中期望的是,前2行之间的' --- '
{
"date":"2015-09-24",
"title":"Getting Started with Git",
"template":"post",
"thumbnail":"content/thumbnails/test.jpeg",
"slug":"getting-started-with-git",
"categories":[ "cat1", "Focus", "Mustang" ],
"tags":[ "Fiesta", "Focus", "Mustang" ]
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现它?使用awk,只有当我将 ' --- '替换为诸如 'start'/'end' 之类的字符串时,我才能实现这一点。
awk '/start/{f=1;next} /end/{f=0;exit} f' $FILE_PATH
Run Code Online (Sandbox Code Playgroud)