Note that there are some explanatory texts on larger screens.

plurals
  1. POFormatting git log output with sed/awk/grep
    primarykey
    data
    text
    <p><strong>Summary / 'gist of' version,</strong></p> <p>if I have a set of messages with subject <code>[SUB]</code> and body <code>[BODY]</code> like below, How can I add a newline after the subject <em>only if <code>[BODY]</code> exists</em> (And replace the place holders with <code>*</code>)</p> <pre><code>[SUB] some subject. [BODY] some body lines with newline chars and !@@# bunch of other *#@ chars without [(BODY)] or [(SUB)]... and more stuff [SUB] Another subject. with no body [BODY] [SUB] another [BODY] some body. </code></pre> <p>I want this to be formatted like</p> <pre><code>* some subject. some body lines with newline chars and !@@# bunch of other *#@ chars without [(BODY)] or [(SUB)]... and more stuff * Another subject. with no body * another some body. </code></pre> <hr> <p><strong>What I really wanna do,</strong></p> <p>So I am trying to auto-generate my CHANGELOG.md file from the <code>git log</code> output. The problem is, I need to put newline char only if the body of the commit message is non empty.</p> <p>The current code looks like this, (broken into two lines)</p> <pre><code>git log v0.1.0..v0.1.2 --no-merges --pretty=format:'* %s -- %cn | \ [%h](http://github.com/../../commit/%H) %n%b' | grep -v Minor | grep . &gt;&gt; CHANGELOG.md </code></pre> <p>and a sample output,</p> <pre><code>* Added run information display (0.1.2) -- ... | [f9b1f6c](http://github.com/../../commit/...) + Added runs page to show a list of all the runs and run inforation, include sorting and global filtering. + Updated run information display panel on the run-info page + Changed the links and their names around. * Update README.md -- abc | [2a90998](http://github.com/../../commit/...) * Update README.md -- xt | [00369bd](http://github.com/../../commit/...) </code></pre> <p>You see here, the lines starting with the <code>*</code> are the commits, and the lines starting on <code>+</code> are just a part of the body for the first commit. Right now it adds a <code>%n</code> (newline) in front of all the body sections regardless of whether it's empty or not. I want to add this ONLY if its non empty (probably even after removing the whitespaces)</p> <p>How would I achieve this? my knowledge of <code>sed</code> and <code>awk</code> is almost non-existing, and trying to learn didn't help much. </p> <p>(I will can make sure all the code in the body is indented, so it wont confuse list of commits with lists in the body)</p> <hr> <p><strong>My Answer</strong></p> <p>i'm sure jthills answer is correct (and maye even a better way to do it), but while I was looking to figure out what his meant, i came up wit this. Hope it will help myself or someone in he future,</p> <p>I am pasting the full shell script that I used,</p> <pre><code>mv CHANGELOG.md CHANGELOG.md.temp printf '### Version '$1' \n\n' &gt; CHANGELOG.md git log $2..$1 --no-merges --pretty=format:'[SUB]%s -- %cn | \ [%h](http://github.com/&lt;user&gt;/&lt;gitrepo&gt;/commit/%H) [BODY]%b' | grep -v Minor | \ sed '{:q;N;s/\s*\[BODY\][\n\s]*\[SUB\]/\n\[SUB\]/;b q}' | \ sed 's/\[SUB\]/* /g' | sed 's/\[BODY\]/\n\n/'&gt;&gt; CHANGELOG.md cat CHANGELOG.md.temp &gt;&gt; CHANGELOG.md rm CHANGELOG.md.temp </code></pre> <p>I am basically prepending the new commit log to the CHANGELOG.md using the temp file. Please feel free to suggest shorter versions for this 3 <code>sed</code> commands</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload