Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure if I understand your requirements correctly but I came up with this simple proof-of-concept, which seems reasonably fast to me. Mind you, it's not written in Java :(</p> <pre><code> awk '/^add row table:/{printf "%06d|%s\n", hash[$3], $0; next} /^add table:/{hash[$2]=NR} {printf "%06d|%s\n", NR, $0}' data | sort -sn | cut -f2 -d'|' </code></pre> <p>The "algorithm" is simple: keep a hash table from table names to line number. Every time you see a new table definition, insert the current line number into the hash table. For every line other than <code>add row</code> lines, output the line number as a prefix to the line; for <code>add row</code> lines, look the table name up in the hash table and use that instead of the line number. Then sort the output with a stable sort. [notes 1 and 2]</p> <p>I tested it with this data file, which has two tables:</p> <pre><code>add header: "Smoke Testing Report for ..... (app name)" add subheader: "on .... (date)" add table:summary header="Summary" columns: 2 add title : "Login page" add table:other header="Other" columns: 1 add screenshot : "C:/projects/SmokingCPOII/geb-reports/Into_Login_page.png" newpage ... 1 ... 2 add title : "Entitlements Before Submit" add screenshot : "C:/projects/SmokingCPOII/geb-reports/Entitlements Before Submit.png" newpage add title : "End" add screenshot : "C:/projects/SmokingCPOII/geb-reports/end.png" newpage ... 3 add row table:other values: "Other 1" ... 4 add row table:summary values: "Entitlements Test, Pass" ... 5 ... 6 add row table:other values: "Other before 2" add row table:other values: "Other 2" add row table:other values: "Other after 2" ... 6a add row table:summary values: "Another Test, Pass" ... 7 ... 8 add row table:summary values: "Yet Another Test, Fail" </code></pre> <p>and it produced:</p> <pre><code>add header: "Smoke Testing Report for ..... (app name)" add subheader: "on .... (date)" add table:summary header="Summary" columns: 2 add row table:summary values: "Entitlements Test, Pass" add row table:summary values: "Another Test, Pass" add row table:summary values: "Yet Another Test, Fail" add title : "Login page" add table:other header="Other" columns: 1 add row table:other values: "Other 1" add row table:other values: "Other before 2" add row table:other values: "Other 2" add row table:other values: "Other after 2" add screenshot : "C:/projects/SmokingCPOII/geb-reports/Into_Login_page.png" newpage ... 1 ... 2 add title : "Entitlements Before Submit" add screenshot : "C:/projects/SmokingCPOII/geb-reports/Entitlements Before Submit.png" newpage add title : "End" add screenshot : "C:/projects/SmokingCPOII/geb-reports/end.png" newpage ... 3 ... 4 ... 5 ... 6 ... 6a ... 7 ... 8 </code></pre> <hr> <p>Note 1: It would be good to check to make sure the table name exists when an add row is encountered.</p> <p>Note 2: It would be possible to keep both the line number and the number of <code>add row</code> lines seen in the hash table, updating the count each time you see a new one, in which case you wouldn't have to worry about a stable sort, although I don't think it's a problem to find stable sorts so I'd avoid the complication.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload