cat - | gawk '{gsub(/[ \t]*$/,""); Line[++N]=$0; Size=length($0); Max = Size > Max ? Size : Max} END {for(I=1; I<=N;I++) {print Line[I] chars(Max-length(Line[I])) " ; " sprintf("%4.0d",I)}} function chars(n, out) {while (n--) {out = out " "}; return out}'