Hi.
The best automatic column alignment tool I have seen is align. It can found at align | freshmeat.net
An example of the use can be seen at the end of this script, using the frans split and paste method for this dataset:
#!/usr/bin/env bash
# @(#) s1 Demonstrate split, paste, align.
# See: http://freshmeat.net/projects/align
# Uncomment to run script as external user.
# export PATH="/usr/local/bin:/usr/bin:/bin"
# Infrastructure details, environment, commands for forum posts.
set +o nounset
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo ; echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
c=$( ps | grep $$ | awk '{print $NF}' )
version >/dev/null 2>&1 && s=$(_eat $0 $1) || s=""
[ "$c" = "$s" ] && p="$s" || p="$c"
version >/dev/null 2>&1 && version "=o" $p specimen split paste align
set -o nounset
FILE1=${1-data1}
shift
FILE2=${1-data2}
# Sample data files with head / tail if specimen fails.
echo
specimen $FILE1 $FILE2 \
|| { echo "(head/tail)"; head -n 5 $FILE1 $FILE2; echo " ||" ;\
tail -n 5 $FILE1 $FILE2; }
# Remove debris from previous runs.
rm xa?
echo
echo " Results:"
# split -l 10 Table_data.txt
# paste Table_Name.txt xaa xab xac
# paste data1 xaa xab xac |
split -l 10 data2
paste data1 xac xab xaa |
align -st
exit 0
Producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
GNU bash 3.2.39
specimen (local) 1.17
split (GNU coreutils) 6.10
paste (GNU coreutils) 6.10
align 1.7.0
Whole: 5:0:5 of 10 lines in file "data1"
table
table1
table1111
table2
table3
table four
table five
table6
some_more_table7
yet ANother_last TAble
Edges: 5:0:5 of 30 lines in file "data2"
490
7127
399
0
1691
---
7798
461
29
30522
462
Results:
table 897 897 490
table1 8642 8642 7127
table1111 888 888 399
table2 50 50 0
table3 25597 25597 1691
table four 7798 7798 1691
table five 461 461 3513
table6 29 29 152
some_more_table7 30522 30522 1691
yet ANother_last TAble 462 462 3513
As you can see it recognizes fields as alphabetic or numeric, and, with the separator option, will split fields by TABs. I adjusted the settings of paste to correspond to the output that the OP last displayed.
Adding column headings, if desired, is left as an exercise.
Best wishes ... cheers, drl
Note 1: the visual alignment of the output looks off in the second-last line compared to my terminal. The default join scheme is a combination of TAB and SPACE characters, so it looks to me as if the forum CODE block SPACE characters are somehow different in size from my terminal. I looked at the raw output and there are TABs between the alpha field and the first numeric column, but SPACES (as they should be) between the numeric columns. I'll continue to look at it, but it appears OK on my display. This is the first that I have noticed such an anomaly.
Note 2: The second last line does not include a TAB, only SPACES after the label, so I think that that is the source on the visual issue.
Note 3: Shortening the label in question produces:
table 897 897 490
table1 8642 8642 7127
table1111 888 888 399
table2 50 50 0
table3 25597 25597 1691
table four 7798 7798 1691
table five 461 461 3513
table6 29 29 152
ome_more_table7 30522 30522 1691
yet ANother_last TAble 462 462 3513
for which align then adds a TAB in that line, and columns appear aligned here. In both cases the output is visually aligned at my work display. This leads me to believe that SPACEs have a different value in CODE blocks compared to my workstation environment. I haven't used anything else other than Debian to look at this thread, so I suppose it is possible that the software chain is distorting the image for me, and that it appears OK to others. Perhaps I'll try looking at it with a Mac and a browser different from Firefox ( or Iceweasel, as it is known in Debian-land )
Note 4: From Mac OS X, Safari, both displays look fine, so the problem is on my end, somewhere in the browser or X. I may look at it more, but the issue is not critical for me.
Note 5: Back on Linux, browser Galeon. Both displays are way off.
Note 6: Linux, epiphany-browser. First display off, second OK. Seems to point to X and / or fonts.