0

please see below :

echo "r22543 | foobar | 2016-03-08 17:17:02 +0800  | 1 line" | egrep -o 'r[0-9]+' | egrep -o '[0-9]+'
22543

Does exist more convenient manner to get the svn revision number?

zhuguowei
  • 7,803
  • 13
  • 62
  • 94

3 Answers3

0

could use pcregrep, see below

 echo 'r123456 foo 2016-03-17' | pcregrep -o1 'r([0-9]+)'
 123456

I see it from Capturing Groups From a Grep RegEx

Community
  • 1
  • 1
zhuguowei
  • 7,803
  • 13
  • 62
  • 94
0

Use --xml command line option and parse the xml'ed output instead of grepping.

svn log https://svn.example.com/myrepo --xml

<?xml version="1.0" encoding="UTF-8"?>
<log>
<logentry
   revision="123">
<author>MyAuthor</author>
<date>2016-03-16T14:05:26.310474Z</date>
<msg>Created folder 'foo'.</msg>
</logentry>
</log>
bahrep
  • 27,991
  • 12
  • 99
  • 140
0

Quite easily done with good old sed:

echo "r22543 | foobar | 2016-03-08 17:17:02 +0800  | 1 line" | sed 's/^r\([^[:space:]]\+\).*/\1/' 
dekkard
  • 4,015
  • 1
  • 14
  • 25