Как насчет однострочного bash?
while read L; do case $L in [A-Z]*) echo ;; esac; echo -n "$L "; done; echo