LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Table format with ShellScript (https://www.linuxquestions.org/questions/linux-general-1/table-format-with-shellscript-322309/)

paraiso 05-11-2005 05:31 AM

Table format with ShellScript
 
From within the shellscript I'd like first to create a file with a table containing two headers( path-name, type) and then feed those columns with the result from the following code:


Code:

file $1/*|tee list_file

The final result should look something like that but with more space between the headers and columns :

-----------------------------------------------
path-name type
-----------------------------------------------
/home/file ASCII
/home/file2 Texte file
/home/file3.htm HTML document text
-----------------------------------------------

I tried the following code but that doesn't do the trick:

Code:

file $1/*|tee list_file | awk 'BEGIN {print "Path-Name\t\t\tType\n--------------------------------------------"} {print $1"\t"$2} \
END {print "-----------------------------"}' list_file

Help! Thanks

theYinYeti 05-11-2005 05:46 AM

Look into awk's ability to handle fixed-width fields.

Yves.

paraiso 05-11-2005 06:39 AM

Hello Yves,

The truth is that I 've been unable to get the table with the ouput content. I tried that but it still don't work:

Code:


#!/bin/bash

file $1/*|tee file_list

awk 'BEGIN { print "Path-Name Type"
              print "--------- -----"}
          { print $1, "      ", $2 }' file_list

:confused:


All times are GMT -5. The time now is 11:03 AM.