Skip to main content
4 of 4
added 21 characters in body
ata
  • 801
  • 5
  • 8
 sed -r 's/([^John] )Smith/\1John/g;s/([^Jane] )Johnson/\1Jane/g'

The () will capture the non-Firstname before a LastName, so they are backref'd in the replacement.

Edit

@manatwork,gilles

You're right. How about

sed -r 's/(John Smith)/temp1/g;s/Smith/John/g;s/temp1/John Smith/g'

This seems to do the trick.

ata
  • 801
  • 5
  • 8