1

I have a variable full of text, its actually a git log. Each line of the git log has an id (a JIRA id), which is either IPAD or MIPO.

I want to filter the git output and only show one or the other

So far I have this:

RAW_NOTES=`git log $LAST_REVISION..master --pretty=format:"%h %ar %s"`
echo "Raw git notes: $RAW_NOTES"

then i can filter it using

RELEASE_NOTES=`echo "$RAW_NOTES" | grep "$JIRA_KEY"`
echo $RELEASE_NOTES

However.... RAW_NOTES has nice formatting and line breaks, RELEASE_NOTES loses all my line breaks.

How can I either preserve formatting, or use some other text filtering command to remove certain lines of text that matches.

example input:

IPAD did this
IPAD did that
MIPO Im another comment
IPAD something else
IPAD bla bla
MIPO hello 
MIPO doodle do

and i want the output to be

MIPO Im another comment
MIPO hello 
MIPO doodle do

Thanks

bandejapaisa
  • 26,576
  • 13
  • 94
  • 112

3 Answers3

1

git log provides filtering like so:

git log --grep="$JIRA_KEY"
user123444555621
  • 148,182
  • 27
  • 114
  • 126
1

Try echoing with quotes, like this:

echo "$RELEASE_NOTES"
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • This also solves my problem, but I might as well filter at the source - the git log, as @Pumbaa80 suggested. Thanks – bandejapaisa Jan 11 '12 at 12:49
0

Based on your sample input you can try anyone of these -

sed -n '/MIPO/p' filename

sed '/MIPO/!d' filename

awk '/MIPO/' filename

grep "MIPO" filename
jaypal singh
  • 74,723
  • 23
  • 102
  • 147