bandejapaisa
bandejapaisa

Reputation: 26952

bash - grep? sed? to remove lines of text from a variable

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

Upvotes: 1

Views: 896

Answers (3)

jaypal singh
jaypal singh

Reputation: 77105

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

Upvotes: 0

dogbane
dogbane

Reputation: 274630

Try echoing with quotes, like this:

echo "$RELEASE_NOTES"

Upvotes: 1

user123444555621
user123444555621

Reputation: 153006

git log provides filtering like so:

git log --grep="$JIRA_KEY"

Upvotes: 1

Related Questions