Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active March 23, 2023 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/57accaf446cf3e7974cd01d57158532c to your computer and use it in GitHub Desktop.
Save Integralist/57accaf446cf3e7974cd01d57158532c to your computer and use it in GitHub Desktop.
[AWK extract first changelog entry] #awk #changelog

We want just the 'v1.0.0-beta.2' changelog block, not 'v1.0.0-beta.1'...

# Changelog

## [v1.0.0-beta.2](...)

**Bug fixes:**

- ...

**Enhancements:**

- ...
- ...

**Documentation:**

- ...
- ...
- ...

## [v1.0.0-beta.1](...)

**Enhancements:**

* More stuff

...

The following awk script does this for us...

cat CHANGELOG.md | awk '/^##/{block++} {if (block==1) {print}}'

Awk works by reading the input 'line by line'. Our script checks if the conditional pattern ^## matches, which is the start of the changelog entry, and if so it increments the variable block. Next, it checks the variable value and prints each line as long as the variable is equal to 1.

The moment we reach the next changelog entry, the block variable will be incremented to 2 and so the block that prints each line will not execute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment