Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Merge cells in all rows of a HTML table dynamically. Post 303012330 by RudiC on Friday 2nd of February 2018 08:20:23 AM
Old 02-02-2018
Different approach, hopefully simpler:
Code:
tac file | awk '
BEGIN   {
         FS=","
#        print "MIME-Version: 1.0"
#        print "Content-Type: text/html"
#        print "Content-Disposition: inline"
         print "</TABLE></BODY></HTML>"
        }

NR > 1  {printf "<TR>" 
         for (i=1; i<=NF; i++)  {if ($i != LAST[i])     {printf "<TD "
                                                         if (ROWSPAN[i] > 1) printf "rowspan=%s", ROWSPAN[i]
                                                         printf ">%s</TD>", LAST[i]
                                                         ROWSPAN[i] = 0
                                                        }
                                 ROWSPAN[i]++
                                }
         print "</TR>"
        }

        {split ($0, LAST)
        }

NR == 1 {for (i=1; i<=NF; i++) ROWSPAN[i]++
        }

END     {for (i=1; i<=NF; i++)
         printf "<TH>%s</TH>", LAST[i]
         print ""
         print "<HTML><BODY><TABLE border=1>"
        }

' | tac

Pls. test and report back.


EDIT: Or, still a tad simpler,
Code:
tac file | awk '
BEGIN   {
         FS=","
#        print "MIME-Version: 1.0"
#        print "Content-Type: text/html"
#        print "Content-Disposition: inline"
         print "</TABLE></BODY></HTML>"
        }

NR > 1  {printf "<TR>" 
         for (i=1; i<=NF; i++)  {if ($i != LAST[i])     {printf "<TD "
                                                         if (ROWSPAN[i] > 1) printf "rowspan=%s", ROWSPAN[i]
                                                         printf ">%s</TD>", LAST[i]
                                                         ROWSPAN[i] = 0
                                                        }
                                }
         print "</TR>"
        }

        {for (i=split ($0, LAST); i; i--) ROWSPAN[i]++
        }

END     {for (i=1; i<=NF; i++)
         printf "<TH>%s</TH>", LAST[i]
         print ""
         print "<HTML><BODY><TABLE border=1>"
        }

' | tac


Last edited by RudiC; 02-02-2018 at 09:25 AM..
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting table cells in a script

I'd like to use sed or awk to do this but I'm weak on both along with RE. Looking for a way with sed or awk to count for the 7th table data within a table row and if the condition is met to delete "<td>and everything in between </td>". Since the table header start on a specific line each time, that... (15 Replies)
Discussion started by: phpfreak
15 Replies

2. Shell Programming and Scripting

How to merge rows into columns ????

Hi guz I want to merge multiple rows into a multiple columns based on the first column. The file has symbol // I want to break the symbool // and I nedd exactlynew column at that point the output will be like this please guyz help in this isssue!!!!! merging rows into columns ... (4 Replies)
Discussion started by: bogu0001
4 Replies

3. Programming

How do I change html style dynamically

I've got the following form element in a template driven web page... <INPUT type="text" class="normal" id="LastName" name="LastName" value="{LastName}"> The stylesheet description is simply... input.normal { width: 250; } I want to change the background colour of the input box after the user... (0 Replies)
Discussion started by: JerryHone
0 Replies

4. Shell Programming and Scripting

Merge two cells in excel via UNIX?

Hi UNIX Gods! Is it possible to merge two cells in .csv file using unix commands? Imagine that this is my present csv file opened via excel: Gate Reports| | fatal alerts | 200 | is is possible to make it look like this using unix? Gate Reports | fatal... (1 Reply)
Discussion started by: 4dirk1
1 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. Programming

Perl script to merge cells in column1 which has same strings, for all sheets in a excel workbook

Perl script to merge cells ---------- Post updated at 12:59 AM ---------- Previous update was at 12:54 AM ---------- I am using below code to read files from a dir and print to excel. open(my $in, '<', $file) or die "Could not open file: $!"; my $rowCount = 0; my $colCount = 0;... (11 Replies)
Discussion started by: Jack_Bruce
11 Replies

7. UNIX for Beginners Questions & Answers

Putting query result dynamically to one cell of table from shell

I have to send a data in mail table format.only one cell need to get dynamically from query. my code is like (echo '<table boarder="1"> echo '<tr><td>stock</td><td>/path</td><td>.........</td></tr>' echo '</table> )sendmail.. in ......... I am trying to get query result.By putting query... (2 Replies)
Discussion started by: meera_123
2 Replies

8. Shell Programming and Scripting

Parameterizing to dynamically generate the extract file from Oracle table using Shell Script

I have below 2 requirements for parameterize the generate the extract file from Oracle table using Shell Script. Could you please help me by modifying the script and show me how to execute it. First Requirement: I have a requirement where I need to parameterize to generate one... (0 Replies)
Discussion started by: hareshvikram
0 Replies

9. UNIX for Beginners Questions & Answers

Remove duplicates in a dataframe (table) keeping all the different cells of just one of the columns

Hello all, I need to filter a dataframe composed of several columns of data to remove the duplicates according to one of the columns. I did it with pandas. In the main time, I need that the last column that contains all different data ( not redundant) is conserved in the output like this: A ... (5 Replies)
Discussion started by: pedro88
5 Replies

10. UNIX for Beginners Questions & Answers

Merge Multiple html files into one

Hi all I have written some code to write my output in html. As i have multiple servers, need to generate single html file. but my code is generating html file for each server. I have merged the files using below code. cat /home/*_FinalData.html > /home/MergedFinalData.html But how to... (1 Reply)
Discussion started by: Snehasish
1 Replies
Layout::Manager::Grid(3pm)				User Contributed Perl Documentation				Layout::Manager::Grid(3pm)

NAME
Layout::Manager::Grid - Simple grid-based layout manager. DESCRIPTION
Layout::Manager::Grid is a layout manager places components into evenly divided cells. When you instantiate a Grid manager, you must supply it with a count of how many rows and columns it will have. For example, a Grid with 1 column and 2 rows would look like: +--------------------------------+ | | | component 1 | | | +--------------------------------+ | | | component 2 | | | +--------------------------------+ The container is divided into as many <rows> * <columns> cells, with each taking up an equal amount of space. A grid with 3 columns and 2 rows would create 6 cells that consume 33% of the width and 50% of the height. Components are placed by specifying the cell they reside in via the row and column number. $container->add_component($comp, { row => 0, column => 3 }); $container->add_component($comp, { row => 0, column => 2, height => 2 }); Optionally, you may choose to override the default "width" or "height" of 1. Setting it to a something else will cause the component to consume that many rows or columns worth of space. Grid is similar to Java's GridLayout <http://java.sun.com/docs/books/tutorial/uiswing/layout/grid.html>. SYNOPSIS
$cont->add_component($comp1, { row => 0, column => 1 }); $cont->add_component($comp2, { row => 0, column => 2 }); my $lm = Layout::Manager::Grid->new(rows => 1, columns => 2); $lm->do_layout($con); DYNAMIC SIZING If the container that the Grid is manging does not have one or both of it's dimensions set, Grid will compute the appropriate sizes. The simple way for me to avoid writing a long explanation is to say it works similar to HTML tables. Rows will become as big as their biggest consituent, as will columns. It is common to add a Grid-managed component to a scene with only one of it's dimensions set. ATTRIBUTES
columns The number of columns in this Grid. rows The number of rows in this Grid. METHODS
do_layout Size and position the components in this layout. AUTHOR
Cory Watson, "<gphat@cpan.org>" COPYRIGHT &; LICENSE Copyright 2008 - 2010 Cory G Watson This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.3 2011-05-16 Layout::Manager::Grid(3pm)
All times are GMT -4. The time now is 09:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy