displaying output in a table.

Hello,

I've just finished my first script (about displaying open ports on the computer and who opened them) and everything is fine with it but I want to style it a little bit just for the sake of learning how to do this.
What I want to do is make the display like the one of ps, for example, i.e make it look like a table:

port         process              files
port1        pr1                    #of files   
port2

I've tried setting the port process and files with awk '{print "process" "port"}' and manipulating the FS but it is way not I wanted to achieve. Could anyone outline me the process of creating a table? Or even redirect me to some good reference on the web because I couldn't find one except for the Gawk variables but I can't figure it out from there.
Here is my source in case it would be easier for you this way:

#!/bin/bash
echo
echo This script will find all the open ports on a computer.
echo It will also show the process that has opened each one and the number of files opened per process.
echo
echo

showProcesses()
{
	netstat -atuv | awk '{print $4}' > ports.list
	lsof -i < ports.list | awk 'NR>1{print $1}'
}

showNumberOfFiles()
{
	lsof -i < ports.list | awk 'NR>1{print $2}' > files.list
	while read pid; do
	lsof -p $pid | awk '{print $1}' > numberoffiles.list
	wc -l < numberoffiles.list
	done < files.list
}

echo Open ports on your computer:
echo

netstat -tuv | awk 'NR>2{print $4}'

echo
echo
echo Processes on each port:
echo

showProcesses

echo
echo
echo Number of files per process:
echo

showNumberOfFiles

Try using tabs instead of spaces, to align the columns.

I've tried using awk'{print "port" "process" "files"}' but it is looped like this forever and even if I manage to do this afterwards I can't place the rest of the output on one line.
Is there a way for example of creating a table with awk by specifiying what goes in the fist column, what goes in the second, etc. I've read about the $1, $2, but as far as I understood this works only for formatting the output of a command not for inputting text into columns 1,2, etc.

If you have used the printf formating in C, you can use the same this here for column alignments.

$ echo "Hai" | nawk '{
> printf("==========================================\n");
> printf("|%10s|%10s|%10s|%10s|\n","11","12","13","14");
> printf("|%10s|%10s|%10s|%10s|\n","21","22","23","24");
> printf("==========================================\n");
> }'
==========================================
|        11|        12|        13|        14|
|        21|        22|        23|        24|
==========================================

mahendramahendr,
use vBcodes for proper post formating.

Thanks mahendramahendr, I will try this when I'm at home. I found a very simple way of doing this with a program called paste- just paste file1 file2 file3 and it makes them as a table. It's great but screws up a little bit just in one case: when there is more than one process at a port. Then the allignment is not that good, but I can live with it :).
Though, if anyone knows whether this can be fixed with paste only or has a different approach in mind, I would appreciate it.

Kindest regards,
Valentin

Thanks vgersh99... This stuff is excellent..