Itinerate throught HTML table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Itinerate throught HTML table
# 1  
Old 03-22-2010
Itinerate throught HTML table

HI all,

HTML Code:
<html>
<body>
  <div>
  <table id="orderList">
    <thead>
      <tr>
        <th>order number</th>
        <th>order type</th>
        <th>product type</th>
        <th>status</th>
        <th>status date</th>
      </tr>
    </thead>
    <tbody>
      <tr class="odd">
        <td><span id="orderLink">24978900</a></td>
        <td><span id="orderType">Provide</span></td>
        <td><span id="productType">Prod1</span></td>
        <td><span id="status">Complete</span></td>
        <td><span id="statusDate">18/12/09</span></td>
        <td><span id="bucket"></span></td>
      </tr><tr class="even">
        <td><span id="orderLink">27004805</a></td>
        <td><span id="orderType">Cease</span></td>
        <td><span id="productType"></span></td>
        <td><span id="status">Rejected</span></td>
        <td><span id="statusDate">17/02/10</span></td>
      </tr>
    </tbody>
  </table>

</div>
</body>
</html>
the desire result will be:

24978900
The last order that is "Complete"; order number is a seq so newer numbers are always at the botton.

Thanks
# 2  
Old 03-22-2010
Quote:
Originally Posted by valigula
...
the desire result will be:

24978900
The last order that is "Complete"; order number is a seq so newer numbers are always at the botton.
...
Here's one way to do it with Perl -

Code:
$
$ cat -n f5
     1  <html>
     2  <body>
     3    <div>
     4    <table id="orderList">
     5      <thead>
     6        <tr>
     7          <th>order number</th>
     8          <th>order type</th>
     9          <th>product type</th>
    10          <th>status</th>
    11          <th>status date</th>
    12        </tr>
    13      </thead>
    14      <tbody>
    15        <tr class="odd">
    16          <td><span id="orderLink">24978900</a></td>
    17          <td><span id="orderType">Provide</span></td>
    18          <td><span id="productType">Prod1</span></td>
    19          <td><span id="status">Complete</span></td>
    20          <td><span id="statusDate">18/12/09</span></td>
    21          <td><span id="bucket"></span></td>
    22        </tr><tr class="even">
    23          <td><span id="orderLink">27004805</a></td>
    24          <td><span id="orderType">Cease</span></td>
    25          <td><span id="productType"></span></td>
    26          <td><span id="status">Rejected</span></td>
    27          <td><span id="statusDate">17/02/10</span></td>
    28        </tr>
    29      </tbody>
    30    </table>
    31
    32  </div>
    33  </body>
    34  </html>
$
$ perl -lne 'BEGIN{undef $/}while (/.*<tr.*?"orderLink">(\d+)<.*?>Complete<.*?\/tr>.*/msg){print $1}' f5
24978900
$
$

tyler_durden

Last edited by durden_tyler; 03-22-2010 at 02:32 PM..
# 3  
Old 03-22-2010
Actually after playing a little bit with AWK, i found

Code:
$ awk -F"[><]" ' /orderLink/ { f=1; _ord=$5; } f && /status/ { $5="Complete"; f =0; print  _ord", " $5}'  /tmp/9054329.htm | tail -1

Thanks

Last edited by Scott; 03-22-2010 at 08:52 PM.. Reason: Please use code tags
# 4  
Old 03-22-2010
Is the HTML file local (ie, really a file) or on the web (ie, something you need to use wget to get?)

This PRE regex would get the number you want from that data:

Code:
/<html>.*?<td><span id="orderLink">(.*?)</a>/s

What do you mean by interate? What are the conditions for what you are looking for or rejecting?

Please be more specific.
# 5  
Old 03-22-2010
On similar lines as the awk script -

Code:
$
$ perl -lne '/.*orderLink">(\d+)<.*/ and $x=$1; /.*>Complete<.*/ and print $x' f5
24978900
$

tyler_durden
# 6  
Old 03-22-2010
Quote:
Originally Posted by drewk
Is the HTML file local (ie, really a file) or on the web (ie, something you need to use wget to get?)

This PRE regex would get the number you want from that data:

Code:
/<html>.*?<td><span id="orderLink">(.*?)</a>/s

What do you mean by interate? What are the conditions for what you are looking for or rejecting?

Please be more specific.
Hi drewk ,

The file it is already on my local machine , first use wget to login and download the page i was need. Did it this way mainly because did not know how to do it online ( without downloading the file). Some people mention using links maybe for the next version Smilie .
Sorry about my mispeling "itinerate".

Thanks
# 7  
Old 03-22-2010
OK -- itinerate Smilie

Try Tyler's perl script (either) with wget or curl:

Code:
curl "http://www.yururl.com" | perl -lne 'BEGIN{undef $/}while (/.*<tr.*?"orderLink">(\d+)<.*?>Complete<.*?\/tr>.*/msg){print $1}'

That will download and itinerate
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export HTML table

HI , I have a HTML tables as below. It has 2 tables ,I want to extract the second table . Please help me in doing it. <html> <body> <b><br>Running Date: </b>11-JAN-2019 03:07</br> <h2> Schema mapping and info </h2> <BR><TABLE width="100%" class="x1h" cellpadding="1"... (3 Replies)
Discussion started by: deepti01
3 Replies

2. 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

3. Shell Programming and Scripting

Creating html table from data in file

Hi. I need to create html table from file which contains data. No awk please :) In example, ->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>... (2 Replies)
Discussion started by: Manu1234567
2 Replies

4. Web Development

Help on filtering the table in HTML

1. how to get the filter option on table so that user can enter the fields which ever they want to print only according to the need ? 2.how to print the full fledge table if there is no value in the rows of the table but it should print the whole rows and column in proper tabular form? (2 Replies)
Discussion started by: sidhi
2 Replies

5. Shell Programming and Scripting

Get HTML table

Hi all, I have a html that contains several tables in it. Need to extract the data from one of them named "orderList". Is it any easy way without using loops. Thanks (4 Replies)
Discussion started by: valigula
4 Replies

6. Shell Programming and Scripting

help with a bash script to create a html table

Hi guys as the title says i need a little help i have partisally written a bash script to create a table in html so if i use ./test 3,3 i get the following output for the third arguement in the script i wish to include content that will be replace the A characters in the... (2 Replies)
Discussion started by: dunryc
2 Replies

7. 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

8. Shell Programming and Scripting

PHP: Sorting HTML table

Hi All, I have an html table which looks like this: <table align="center" border="1"> <CAPTION><EM>Heading for Table</EM></CAPTION> <tr><td><b>1</b></TD><TD><b>2</b></TD><TD><b>3</b></TD><TD><b>4</b></TD><TD><b>TOTAL</b></TD><TD><b>DATE</b></td></tr> <tr><td>88088283</TD> <TD>87613101</TD>... (1 Reply)
Discussion started by: pondlife
1 Replies

9. Shell Programming and Scripting

Export a HTML table to Xcel

Hello All, I have a perl script that prints a HMTL table. I want to convert this data into a report and this want to export this information into Excel. How can I do this? Regards, garric (3 Replies)
Discussion started by: garric
3 Replies

10. Shell Programming and Scripting

HTML table to CSV

Hi !! I have HTML Tables through which i want to generate graphs, but for creating graphs i need the file in CSV format so can anyone can please help me in how can i convert my HTML table file to CSV format. Thanks in Advance (2 Replies)
Discussion started by: i_priyank
2 Replies
Login or Register to Ask a Question