Using sed to retrieve part of a line

Solution 1:

Here's a regex-free solution, because

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

(take it with a grain of salt)

You can use cut twice:

git svn log --limit=1 --oneline | cut -d ' ' -f 1 | cut -c 2-

The first cut (cut -d ' ' -f 1) sets space as column delimiter and selects only the first column, so r12345. The second cut (cut -c 2-) selects character at position 2 and following (2-).

Solution 2:

You are nearly there

sed -e 's/r\([0-9]*\) .*/\1/'

You have to tell sed both what you want \([0-9]*\) and what you don't want /r & .*/