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:
Code:
#!/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:
Code:
% ./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:
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.
below is the output is ls -l
-rw-r--r-- 1 tonyt staff 3212 Apr 17 1999 file1
-rw-r--r-- 1 tonyt staff 4541 Mar 3 21:08 file2
why the date format is not the same? (6 Replies)
Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command isecho date
`top -b -n1 | grep -e Cpu -e Mem` I get the output in 3 separate lines.Tue Feb 24 15:00:03
Cpu(s): 3.4% us, 8.5% sy .. ..
Mem: 1011480k total, 226928k used, ....... (4 Replies)
Dear all,
I have written a program which access database and displays the values returned by the query . There are 10 columns to be displayed in one row. But am ending with 5 lines displayed on 1st line and the next 5 in the 2nd line.
Ex :
21608 10-20-2007 148 Al's Appliance... (7 Replies)
Hi all,
I have input text file of this format
objectclass:endeavor
pid:12345
postalAddress:379 PROSPECT ST
street:STE B
l:TORRINGTON
st:CT
postalCode:067905238
telephoneNumber:9999999999... (2 Replies)
i am running df -k command on aix machine.
i got the output like this. i need to store into file and send that file into microsoft excel.i need to allign properly.
Filesystem 512 blocks Free % Used Iused %Iused Mounted on
/dev/hd4 262144 126488 52% ... (9 Replies)
Hi,
I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format.
Example:
File.txt
AP|{SSHA}VEEg42CNCghUnGhCVg==
APVG3|{SSHA}XK|"password"
AP3|{SSHA}XK|"This is test"
....
etc
---------
test.sh has... (1 Reply)
Hello Learned People,
Good evening. I have absolutely no idea as how to do this & I admit that I do not know anything in unix. I must learn this one of these days.
Im a help desk incharge today & someone gave me this file to be formatted & I have a file like this.
vi NewFile.txt
232... (8 Replies)
Hi ,
i am generating some data by firing sql query with connecting to the database by my solaris box.
The below one should be the header line of my excel ,here its coming in separate row.
TO_CHAR(C. CURR_EMP_NO
---------- ---------------
LST_NM... (6 Replies)
I have written some scripts that resulted in the table below (Column1 is ITEM, Column2 is Group, Column3 is Category and Column4 is Quantity) but I want the output in another format:
Input:
K123 X CATA 3
K123 Y CATA 4
K123 Z CATA 2
K123 X CATB 5
K123 Y CATB 2
K123 Z CATB 2
B65 M CATB... (7 Replies)
Hello Team,
I have the following details in a txt file (please note the spaces and tabs)
C1 C2 C3
------------------ --------------- -------------
abc, xyz 2 8
pqr 2 ... (9 Replies)