0

I am trying to use sed to get the number of insertions/deletions from diff stat. For example, diffstat gives something like "1 file changed, 2 insertions(+), 1 deletion(-)". How can I retrieve "2" from diffstat using sed? I can't seem to figure it out.

Thanks for your time.

Figured out very simple solution-

sed 's|.*\s\(.*\)\sinsertion.*|\1|'

2 Answers2

1
sed 's/.*, \(.*\) insertions.*/\1/'

Explanation: look for "[anything], [something] insertions[anything]" and replace it with [something]. Might want to pass the diffstat through grep first to isolate this one line.

Jared Casper
  • 170
  • 8
1

Try this:

echo "1 file changed, 2 insertions(+), 1 deletion(-)" | sed -r 's/.*([0-9]+) insertion.*/\1/'
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432