#!/bin/bash
s='John, 1234567
Bob, 2839211
Alex, 2817821
Mary, 9371281'
sed 's/^\([^,]*\), *[0-9]*\([0-9]\{4\}\).*/\1, \2/' <<< "$s"