2

Our buildserver needs to release apps to App Center. App Center allows me to provide a release note file.

The problem is, our ReleaseNotes.md contains ALL the versions and become to big to for App Center to accept it.

The notes are formatted like this:

# Project - Release Notes - Android

## 1.20.2 - 2020-09-11
* [UID-4782] - Connectivity issues fixed

## 1.20.1 - 2020-09-08
 * [UID-4639] - Update Color
 * [UID-4760] - Changed some stuff

How can I grab just the first entry and save it to a file?:

## 1.20.2 - 2020-09-11
 * [UID-4782] - Connectivity issues fixed

and save it to a file?

If looked into tools like awk, grep, sed and pcergrep but I'm not familiar with these in anyway and I have no idea which one would be the right tool for the job.

SEG.Veenstra
  • 718
  • 1
  • 7
  • 18

4 Answers4

2

This awk should get the job done:

awk -v RS= '/^##/{print; exit}' file
## 1.20.2 - 2020-09-11
* [UID-4782] - Connectivity issues fixed
anubhava
  • 761,203
  • 64
  • 569
  • 643
1

Using awk in "paragraph mode" by setting RS to the empty string and then saving it to another file:

awk -v RS= '/issues fixed/' file > file2
## 1.20.2 - 2020-09-11
* [UID-4782] - Connectivity issues fixed
Carlos Pascual
  • 1,106
  • 1
  • 5
  • 8
  • 1
    If I understand this correctly it is depending on the `'issues fixed'` right? But I also need it to work if a new entry is being added which might not contain that. – SEG.Veenstra Oct 20 '20 at 14:31
  • Note that you get the whole paragraph. You can experiment putting something different present in the paragraph, for example /2020-09-11/ You'll get the same, i.e., the whole paragraph. – Carlos Pascual Oct 20 '20 at 17:46
  • Ah yes, I see, but now it's giving me all the paragraphs. I only want the first one. (without knowing what is in it) – SEG.Veenstra Oct 21 '20 at 06:36
1

Using sed:

sed -n '/^##/,/^$/{p;/^$/q;}' input_file > output_file
  • -n: Do not print lines by default.
  • /^##/: Find a line starting with ##.
  • /^$/: Find an empty line.
  • /^##/, /^$/: Together this means for each line between a line starting with ## and an empty line.
  • p: Print the line.
  • /^$/q: If the line is empty quit. We do this because otherwise sed will process the next block of changes.
SEG.Veenstra
  • 718
  • 1
  • 7
  • 18
perreal
  • 94,503
  • 21
  • 155
  • 181
1

So I've did some bash script learning and created the following script:

#!/bin/bash

foundFirstEntry=false

"ReleaseNotes.md" | while read p; do
    if [[ $p = \#\#* ]]
    then
        foundFirstEntry=true
    fi

    if [[ $foundFirstEntry = true && $p = "" ]]
    then
        break
    fi

    if $foundFirstEntry 
    then
        echo "$p"
    fi
done > "ShortReleaseNotes.md" < "ReleaseNotes.md"
SEG.Veenstra
  • 718
  • 1
  • 7
  • 18
  • 1
    That's great. You can remove the cat and change the last line to `done > "ShortReleaseNotes.md" < "ReleaseNotes.md"`. – perreal Oct 20 '20 at 14:41
  • Is that better? If so, can you explain why? – SEG.Veenstra Oct 20 '20 at 14:45
  • 1
    It is better because `cat` needs to be loaded and executed but it is not necessary. see: https://stackoverflow.com/questions/11710552/useless-use-of-cat. – perreal Oct 20 '20 at 14:51