Shell Script Table

Hi,

i need a bit help. I must write a script with shell- and sed-commands, which reads a table from stdin and writes a html-table on stdout (so i can open it with a web browser). The number of columns must be a parameter for the script, so i can start it for example with: "./htmltab.sh 3 <table-data". (sry if my english is bad)

What have you tried?

Not much. I'm searching and reading the whole day but I don't know how to begin. It's difficult to me to understand the whole linux system with STDIN and STDOUT. I'm new with linux. I'm studying and the lessons and tasks we get in Scripting are not very well organised. We must write a script which reads a table like this:

            Name \\t Size \\t Type
              bla \\t 4711 \\t f i l e
          abcde \\t 4096 \\t directory 

and then writes a html-table. We got the structure for the html-table because we never worked with html, but it doesn't helps me a lot...it would be easier to explain the task in german...I know for example how to find and extract words from a text with 'sed' but not how I should read a table and convert it.

Standard input and output amount to pre-opened files. Usually, standard input is connected to your keyboard, and standard output is connected to your screen, but the shell lets you attach them to anything you want like this:

./myscript < inputfile > outputfile

< redirects standard input. Any commands you run in that script, and the read builtin, will read from inputfile instead of the keyboard.

> redirects standard output. Any commands you run, and the echo builtin, will write to outputfile instead of the terminal.

So when they are telling you to read from standard input, they are telling you to just read from the default with read and feed whatever you want into it later.

You use read like

read VAR1 VAR2 VAR3 VAR4

and if the first line is A B C D E, it effectively does VAR1="A"; VAR2="B" ; VAR3="C" ; VAR4="D E"

And 'standard output' just means 'print to the terminal with echo or whatever'.

We really can't give you a direct answer, we can give you the tools. And this should really be in the homework forum, please re-post there following the homework template.

1 Like