Creating html table from data in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating html table from data in file
# 1  
Old 10-23-2013
Creating html table from data in file

Hi. I need to create html table from file which contains data. No awk please Smilie In example,

Code:
->cat file
num1 num2 num3
23 3 5 
2 3 4

(between numbers and words single TAB).
after running mycode i need to get (heading is the first line):
<table> <tr><th>num1</th><th>num2</th><th>num3</th></tr>
<tr><td>23</td><td>3</td><td>5</td></tr>
<tr><td>2</td><td>3</td><td>4</td></tr>
</table>

My code looks like this....but I stopped here...
Code:
for i in $*
do
echo "<table>"
while read line
do

for word in $line
do
echo "<tr>"
echo $word
echo "</tr>"
#echo $line
echo "</table>"

done
done<$i

done


Last edited by Manu1234567; 10-23-2013 at 10:03 PM..
# 2  
Old 10-23-2013
Hi.

When you have restrictions it is useful to say why you must or must not use certain approaches.

See the links at the bottom of this thread, as well as https://www.unix.com/shell-programmin...html-file.html for some ideas ... cheers, drl
# 3  
Old 10-24-2013
Try this:

Code:
for i in $*
do
    echo "<table>"
    ln=1
    OIFS=$IFS
    IFS=$'\t'
    while read line
    do
        echo "<tr>"
        for word in $line
        do
            if [ $ln -eq 1 ]
            then
                echo "<th>$word</th>"
            else
                echo "<td>$word</td>"
            fi
        done
        echo "</tr>"
        let ln=ln+1
    done<$i
    IFS=$OIFS
    echo "</table>"
done


Last edited by Chubler_XL; 10-24-2013 at 12:21 AM.. Reason: Update to support space in data (set/reset IFS)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

Parsing - export html table data as .csv file?

Hi all, Is there any out there have a brilliant idea on how to export html table data as .csv or write to txt file with separated comma and also get the filename of link from every table and put one line per rows each table. Please see the attached html and PNG of what it looks like. ... (7 Replies)
Discussion started by: lxdorney
7 Replies

2. UNIX for Dummies Questions & Answers

Convert Txt file to HTML table and email

Hi all I need help converting a text file into a html table in bash and I need to email this table. The text file looks like the below. Two columns with multiple rows. Top row being header. Application Name Application Status Application 1 Open Application 2 ... (2 Replies)
Discussion started by: hitmanjd
2 Replies

3. UNIX for Dummies Questions & Answers

Extract table from an HTML file

I want to extract a table from an HTML file. the table starts with <table class="tableinfo" and ends with next closing table tag </table> how can I do this with awk/sed... ---------- Post updated at 04:34 PM ---------- Previous update was at 04:28 PM ---------- also I want to... (4 Replies)
Discussion started by: koutroul
4 Replies

4. Shell Programming and Scripting

Input data of a file from perl into HTML table

Hi , I need an help in perl scripting. I have an perl script written and i have an for loop in that ,where as it writes some data to a file and it has details like below. cat out.txt This is the first line this is the second line. .....Now, this file needs to be send in mail in HTML... (2 Replies)
Discussion started by: scott_cog
2 Replies

5. Shell Programming and Scripting

extract complex data from html table rows

I have bash, awk, and sed available on my portable device. I need to extract 10 fields from each table row from a web page that looks like this: </tr> <tr> <td>28 Apr</td> <td><a... (6 Replies)
Discussion started by: rickgtx
6 Replies

6. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

7. UNIX for Dummies Questions & Answers

Bash script to insert data into an html table

hi, I need to create a bash shell script which picks up data from a text file and in the output file puts it into an html made table. I have to use sed and awk utilties to do this the input text file will contain data in the format: job name para1 para2 para3 para4 para4 1 ... (1 Reply)
Discussion started by: intern123
1 Replies

8. Shell Programming and Scripting

Converting html table data into multiple variables.

Hi, Basically what I am trying to do is the following. I have created a shell script to grab timetabling information from a website using curl then I crop out only the data I need which is a table based on the current date. It leaves me with a file that has the table I want plus a small amount... (2 Replies)
Discussion started by: domsmith
2 Replies

9. Shell Programming and Scripting

Format txt file as html table

I have a short time to solve a problem, so I need some help. I've searched the forum, but I couldn't find a solution to my problem. I made a script to filter some text and now I have a new requirement to make it available as html table. Problem is that I more than one files with different set... (2 Replies)
Discussion started by: tetreb
2 Replies
Login or Register to Ask a Question