Assuming there's the
|a at the start of the line, let's change that pattern a bit:
$ echo '|a Milton, John, |d 1608-1674.' | sed -E 's/^\|a ([^,]*), *([^,]*),.*/\1/'
sed -E uses extended regexes, so we can group with
(...) without backslashes. Then we match the leading
|a and the space, pick everything up to the next comma to a group
([^,]*),, ignore spaces with
␣*, and pick another group the same way as the first. The
,.* eats the rest of the line, and we can replace all of it with the first group
Milton), or the second group
Of course, if the
|a is there to tell us what this particular field contains, and the fields might be in another order (like
|d ... |a ...), then we'd need something different.