Why use three commands when you can use one ;-?
(When it comes to processing text, bailing out to a shell script will almost always be “easier” because Unix has so many tools for text manipulation. But I put “easier” in quotes because you have to find the right incantation, which can tricky, but often not much harder than figuring out how to do it in Keyboard Maestro natively.)