Blech - I completely missed the fact that sed wants '*' and not '+' to match multiple instances. D'oh! This seems to get everything but the last line: sed -e ':a;N;$!ba;s/\([0-9][0-9][0-9][0-9][0-9]\n\)*\([[0-9][0-9][0-9][0-9][0-9]\n\)/\2/g' Chris