The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
Your script already formats the tables at the time it constucts them; the ORS variable evaluates to a newline (and changing it does not really solve anything, at least not trivially).

As a basic principle, you want something like (pseudocode)

Code:
separator=  # nothing
for table in tables
  print separator table.name
  separator=tab # or suitable number of spaces, or something
done
print "\n"

separator=  # nothing
for table in tables
  print separator "-" x (lenght table.name)   # print as many underlines as required
  separator=tab # or suitable number of spaces, or something
done
print "\n"

for i=0 to (however long the longest table is)
  separator=  # nothing
  for table in tables
    print separator
    if (table.value[i])
      table.value[i]
    else
      print ""   # print whitespace if we ran out of values for this table
    separator=tab # or suitable number of spaces, or something
  done
  print "\n"
done
As you can tell, this entails changing your data structure drastically, and possibly even changing to a different language. (Perl or Python would be easier than awk for this I think.)

A less drastic solution would be to output each table to a temporary file and use pr to print it in columnar format. On Linux, I use pr -bt 3 to tabulate into three columns; other platforms offer slightly different options.

Last edited by era; 05-17-2008 at 01:59 AM. Reason: pr -bt3
Reply With Quote