Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7078417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:32:42+00:00 2026-05-28T06:32:42+00:00

I’m pretty familiar with PHP including command line, semi-familiar with BASH scripting, and no

  • 0

I’m pretty familiar with PHP including command line, semi-familiar with BASH scripting, and no experience with Perl or other languages but willing to use whatever works.

The HTML file I am trying to parse is 700,000+ lines, 61MB. I cannot change the source that builds the HTML table, only download the entire table via wget http://10.1.1.2/file.pl.

Here’s an example format of the HTML code that I’m trying to parse:

<HTML>
  <HEAD>
    <TITLE>Objects</TITLE>
    <STYLE type="text/css">
    a:hover
    {
    color:red
    }
    </STYLE>
    </HEAD>
  <BODY>
  <IMG src="http://10.1.1.2/images/logo.gif"/>
  <BR/><BR/>
  <TABLE border="0">
    <TR>
      <TH>Objects</TH>
    </TR>
    <TR>
      <TD><HR style="width:227px"></TD>
    </TR>
  </TABLE>
  <table border=1 cellpadding=5 cellspacing=0><tr><th><b>Subtype</b></th><th><b>Object</b>    </th></tr>
    <tr><td>10GigEthernet</td><td>SNFCCAMK34T-TenGigE0/10/0/0</td></tr>
    <tr><td>10GigEthernet</td><td>SNFCCAMK34T-TenGigE0/13/0/0</td></tr>
    <tr><td>10GigEthernet</td><td>SNFCCAMK34T-TenGigE0/13/3/0</td></tr>
    <tr><td>10GigEthernet</td><td>SNFCCAMK34T-TenGigE0/3/0/0</td></tr>
    <tr><td>10GigEthernet</td><td>SNFCCAMK34T-TenGigE0/3/0/0-5</td></tr>
    ... 700,000 more lines ...
  </table>        </BODY>
</HTML>

What I’d like in the CSV:

Subtype,Object
10GigEthernet,SNFCCAMK34T-TenGigE0/10/0/0
10GigEthernet,SNFCCAMK34T-TenGigE0/13/0/0
10GigEthernet,SNFCCAMK34T-TenGigE0/13/3/0
10GigEthernet,SNFCCAMK34T-TenGigE0/3/0/0
10GigEthernet,SNFCCAMK34T-TenGigE0/3/0/0-5

I’d appreciate any help you can give! Thanks in advance.

Result from @shellter’s code:

# wget http://10.1.1.2/reports/file.pl
--2012-01-19 06:56:59--  http://10.1.1.2/reports/file.pl
Connecting to 10.1.1.2... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified
Saving to: `file.pl'

    [          <=>                          ] 61,000,000  1.01M/s   in 58s     

2012-01-19 06:58:00 (1.01 MB/s) - `file.pl' saved [61000000]

# sed -n '/<\/td>/{
>            s@<tr><td>@@;
>            s@</td>@XaYbZc@;
>            s@<td>@@;
>            s@</td></tr>@@;
>            s/XaYbZc/,/
>            s/^    //
>            p
>           }' file.pl > routerList.csv
# ls -l
total 203408
-rw-r--r--   1 root     root     61000000 Jan 19 06:58 file.pl
-rw-r--r--   1 root     root     42708247 Jan 19 06:58 routerList.csv
# head routerList.csv
10GigEthernetn,SNFCCAMK34T-TenGigE0/10/0/0
10GigEthernetn,SNFCCAMK34T-TenGigE0/13/0/0
10GigEthernetn,SNFCCAMK34T-TenGigE0/13/3/0
10GigEthernetn,SNFCCAMK34T-TenGigE0/3/0/0
10GigEthernetn,SNFCCAMK34T-TenGigE0/3/0/0-5
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:32:43+00:00Added an answer on May 28, 2026 at 6:32 am

    While I have to agree with most of the comments like ‘use a DOM, or XPATH, etc.’,
    you are lucky in this case that all data you want to process is on one line. If there are ever linebreaks anywhere in that data, then this will not work AND it will be essentially impossible to get a working solution is sed. So forwarned of these issues, try this

     wget http://10.1.1.2/file.pl
    
     sed -n '/<\/td>/{
               s@<tr><td>@@;
               s@</td>@XaYbZc@;
               s@<td>@@;
               s@</td></tr>@@;
               s/XaYbZc/,/
               s/^    //
               p
              }' file.pl > routerList.csv
    
    cat routerList.csv
    10GigEthernet,SNFCCAMK34T-TenGigE0/10/0/0
    10GigEthernet,SNFCCAMK34T-TenGigE0/13/0/0
    10GigEthernet,SNFCCAMK34T-TenGigE0/13/3/0
    10GigEthernet,SNFCCAMK34T-TenGigE0/3/0/0
    10GigEthernet,SNFCCAMK34T-TenGigE0/3/0/0-5
    

    The sed script is using the ‘@’ char as the match/replace section delimiter.

    First we take the first <tr><td> on the line and delete it,

    We then take the first </td> and replace it with XaYbZc as a temp marker.

    Remove the remaining opening <td>.

    Remove the trailing </td></tr>

    Replace the temporary XaYbZc with the ‘,’

    Remove 4 spaces at the front of the line.

    Print the buffer. (Done!)

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need to clean up various Word 'smart' characters in user input, including but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.