小编PKV*_*PKV的帖子

获取特殊字符模式之间的行

下面是我的输入文件:

---
{
  "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)

command-line awk text-processing

3
推荐指数
1
解决办法
85
查看次数

标签 统计

awk ×1

command-line ×1

text-processing ×1