Tag: grep

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

Grep for alternative of words

$ cat sample.txt
abc
abc Exception efg
123 ERROR 456
a1 Exception b2 ERROR
1a ERROR 2b Exception
123

$ cat sample.txt | egrep “ERROR|Exception”
abc Exception efg
123 ERROR 456
a1 Exception b2 ERROR
1a ERROR 2b Exception

$ cat sample.txt | egrep –color=always “ERROR|Exception”
abc Exception efg
123 ERROR 456
a1 Exception b2 ERROR
1a ERROR 2b Exception