FWIW I'd recommend writing a proper script for "complex" commands. Sure a simple sed-to-sort pipe is fine, but don't fall into the trap of writing an entire script there, it's gonna be a lot easier for you to maintain this separately and just call it from there.