Splitting csv into 3 tables in html file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Splitting csv into 3 tables in html file
# 1  
Old 07-29-2017
Splitting csv into 3 tables in html file

I have the data in csv in 3 tables. how can I output the same into 3 tables in html.also how can I set the width. tried multiple options . attached is the format.
Code:
 #!/bin/ksh
 awk 'BEGIN{
        FS=","
        print "<HTML><BODY><TABLE border = '1' cellpadding=10 width=100>"
   print "<head><style> table {border-collapse: collapse;} table, td, th {border: 1px solid black;} </style></head>"
     }
     {
        printf "<TR>"
        for(i=1;i<=NF;i++)
          printf "<TD>%s</TD>", $i
        print "</TR>"
     }
     END{
        print "</TABLE></BODY></HTML>"
     }
     ' report.csv > file2.html


Last edited by Scott; 07-29-2017 at 02:43 PM.. Reason: Please use code tags
# 2  
Old 07-29-2017
Your awk needs to be changed slightly and put inside a loop:
Here is a simple sample. It writes everything to single html file, from 3 input files
Code:
#!/bin/ksh
echo "<HTML><BODY>" >> file1.html
for f in report.csv report2.csv  report3.csv   #loop
do

 awk 'BEGIN{
        FS=","
        print "<TABLE border = '1' cellpadding=10 width=100>"
   print "<head><style> table {border-collapse: collapse;} table, td, th {border: 1px solid black;} </style></head>"
     }
     {
        print "<TR>"
        for(i=1;i<=NF;i++)
        {
          printf ("<TD>%s</TD>\n", $i)
        }
        print "</TR>"
     }
     END{ print "</TABLE>" }
     ' "$f"  >> file1.html
done
echo "</BODY></HTML>"  >> file1.html

Please define 'changing width'.
# 3  
Old 07-30-2017
Is it possible to generate from 1 csv instead of 3 csv's?
# 4  
Old 07-30-2017
If you have 3 tables in 1 CSV file, how are the tables separated?

Maybe it would help if you showed us a sample input file and the output you hope to produce from that input.
# 5  
Old 07-30-2017
how can i change the width of the columns in the above.

---------- Post updated at 12:18 PM ---------- Previous update was at 12:17 PM ----------

tables in the csv are separated by space. if that is tough i can output the tables in 3 separate csv's and then create a single html from 3 csv files.

I am still not able to define width of the columns in the above.

---------- Post updated at 12:27 PM ---------- Previous update was at 12:18 PM ----------

print "<head><style> table {border-collapse: collapse; width:150%;} table, td, th {border: 1px solid black;} </style></head>"

when i add the above i changes width for the 1st and 3rd table. not the 2nd table. also how can i change the width for each table separately
# 6  
Old 07-30-2017
Code:
 <table>
  <col width="130">
  <col width="80">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

Or:
Code:
  <colgroup>
    <col span="2" style="background-color:white">
    <col style="background-color:yellow">
  </colgroup>

You can do this. But it requires that you know the max number of columns possible because you specify col value for each column. Empty columns are still that wide, too. colgroup will set the width value for the whole table.

Last edited by jim mcnamara; 07-30-2017 at 01:50 PM..
# 7  
Old 07-30-2017
the above is not working. also i have around 60 columns. cant define for each
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract the tables from html

Hi I have a script which extracts the table from HTML and convert it into .csv. But the problem in the script is if we have 2 tables in HTMl . it takes only the first table. Please help me what changes i need to do in the script to make it read the complete HTML page. Script is as below: ... (10 Replies)
Discussion started by: deepti01
10 Replies

2. Shell Programming and Scripting

Read CSV file and delete hdfs, hive and hbase tables

I have a CSV file with hdfs directories, hive tables and hbase tables. 1. first column - hdfs directories 2. second column - hive tables 3. third column - hbase tables I have to check the csv file and look for the first column and delete the hdfs directory from the hdfs path, now... (2 Replies)
Discussion started by: shivamayam
2 Replies

3. Shell Programming and Scripting

Splitting CSV into variables then to XML file

I have a text file that looks like this: FIELD1, FIELD2, THIS IS FIELD3, FIELD4 FIELD1, FIELD2, THIS IS FIELD3, FIELD4 FIELD1, FIELD2, THIS IS FIELD3, FIELD4 I need it to turn it into an XML file to run against a custom application. My ultimate goal is for it to look like... (15 Replies)
Discussion started by: jeffs42885
15 Replies

4. Shell Programming and Scripting

Splitting input CSV file into 3 files

Hi , I am receiving a CSV file that can vary in number of rows each time. I am supposed to split this file into 3 separate files like this: 1. create a file named 'File1.csv' that will contain first 3 rows of the input file 2. create file named 'File2.csv' that will contain last 3 rows of the... (7 Replies)
Discussion started by: kedrick
7 Replies

5. Shell Programming and Scripting

Script to convert CSV file to HTML

Hi, I have made a a script which creates a csv file as daily database report However i want to covert that csv file to html because csv file does not have a good visibilty. So it is possible to have such csv to html coversion script. Your prompt help much appreciated. Thanks in advance (4 Replies)
Discussion started by: sv0081493
4 Replies

6. UNIX for Advanced & Expert Users

Splitting the single csv file

Hi, I have a requiement where in i will get a single file but there will be mutiple headers. Suppose say for eg: Header1 Data... Data... Header2 Data.. Data.. Header3 Data.. Data.. I want to split each with the corresponding data into a single file. Please let me know how... (1 Reply)
Discussion started by: weknowd
1 Replies

7. UNIX and Linux Applications

Does anybody know how to store my tables to a csv file?

Hi I'm using an oracle database... Lets call it databasename My username and password are the same .... lets all that andrea/andrea So I want to write a script to copy all the data from my table called tablename and store that data to a csv file called filename. I cant seem to get... (2 Replies)
Discussion started by: ladyAnne
2 Replies

8. UNIX for Dummies Questions & Answers

convert csv to html file

Hi All, I am new to this forum,not sure where to post this query...so posted here Kindly need any of your help on the below ------------ I am using shell scripting and trying to convert a csv file to html file... example.csv --------------- Name Country Age Sex Andy India 25 ... (4 Replies)
Discussion started by: sumithra
4 Replies

9. Shell Programming and Scripting

help with splitting a html file up

hi i have a file called t.txt <p>The mayor is <a href="javascript:popupPerso('FichePersonnage.php?login=Yvaine')">Yvaine</a></p><p>The mentor is <a href="javascript:popupPerso(' FichePersonnage.php?login=Chaselambourne')">Chaselambourne</a></p>List of the villagers :<br><div id="Layer1"... (3 Replies)
Discussion started by: jeroen234
3 Replies
Login or Register to Ask a Question