Find and Replace Problem-Statement

On Tuesday, April 25th, I realized that I had set the tags in each blog post incorrectly. I thought they were delimited via commans, when they were actually delimited via an unordered list with the '-' character used as a bullet.

This is a common find/replace problem that can be solved in a variety of ways. It's a good simple problem to regularly solve. Also, it is easily mutated with different find/replace challenges.

The Problem-Statement

A series of blog post files have their tags set incorrectly.

Each file has a list of tags set via:

1
2
3
4
5
---
title: Title
date: date
tags: tag1, tag2, tag3
---

When it should be:

1
2
3
4
5
6
7
8
---
title: Title
date: date
tags:
- tag1
- tag2
- tag3
---

Programmatically fix this incorrect setup.

Mutations

Do It Backwards

Find/replace in the reverse order.

Switch:

1
2
3
4
5
6
7
8
---
title: Title
date: date
tags:
- tag1
- tag2
- tag3
---

to:

1
2
3
4
5
---
title: Title
date: date
tags: tag1, tag2, tag3
---

Sed One-Liner

First attempt did this with two sed commands. It can definitely be done in one.

Attempts

[1]