grep egrep sed match replace part of the text

url=http://svn.dev.mycompany.com/svn/myproject/branches/mybranch
svn log $url -r {2016-12-01}:{2016-12-30} --search Bartosz
------------------------------------------------------------------------
r324 | bartosz@mycompany.com | 2016-12-14 17:11:44 +0100 (Wed, 14 Dec 2016) | 1 line

created mybranch
------------------------------------------------------------------------

expected output:

http://svn.dev.mycompany.com/svn/myproject/branches/mybranch/?p=123 | bartosz@mycompany.com | 2016-12-14 17:11:44 +0100 (Wed, 14 Dec 2016)
url=http://svn.dev.mycompany.com/svn/myproject/branches/mybranch
svn log $url -r {2016-12-01}:{2016-12-30} --search Bartosz | egrep '^r[0-9]+' | sed "s|\(^r\)\([0-9]*\)|$url/?p=\2|" | sed 's/ | [0-9]* line.*$//'

where

egrep '^r[0-9]+'

is equivalent to extended grep -E and matches begging of line with rRev e.g r123

sed "s|\(^r\)\([0-9]*\)|$url/?p=\2|"

– with ‘/’ replaced by ‘|’ and taking only revision number (skipping ‘r’ in the beginning) and adding the url: ‘r123’ -> ‘http://svn.dev.mycompany.com/svn/myproject/branches/mybranch/?p=123’

sed 's/ | [0-9]* line.*$//'

– removes last part of message e.g.: ‘ | 1 line’

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s