Sorting and manipulation of a block of text