Extract table from an HTML file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extract table from an HTML file
# 1  
Old 04-11-2014
Extract table from an HTML file

I want to extract a table from an HTML file. the table starts with


Code:
<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 mention that all text is one line and within the line there is a lot of text before and after the table that should be excluded

Last edited by bartus11; 04-11-2014 at 10:35 AM.. Reason: Please use [code][/code] tags.
# 2  
Old 04-11-2014
Try:
Code:
perl -ln0e '/<table.*?table>/s;print $&' file

# 3  
Old 04-11-2014
but also other tables are included in the line.. so I need the one with
class="tableinfo"
# 4  
Old 04-11-2014
Try:
Code:
perl -ln0e '/<table class="tableinfo".*?table>/s;print $&' file

# 5  
Old 04-11-2014
Quote:
Originally Posted by koutroul
I want to extract a table from an HTML file. the table starts with


Code:
<table class="tableinfo"


and ends with next closing table tag
</table>

how can I do this with awk/sed...
If you are guaranteed to have the complete tag pair on one line, the sed command is easy:

Code:
print - "$line" | sed 's/.*\<table class="tableinfo"//;s/\<\/table\>.*//'

The first substitution cuts off everything before the table starts, the second one everything after the table ends.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert shell script output txt file to html table

My concnern related to the post -Convert shell script output txt file to html table, in this how to print the heading as color. awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' <filename> (8 Replies)
Discussion started by: sarajobmai
8 Replies

2. Linux

Parsing - export html table data as .csv file?

Hi all, Is there any out there have a brilliant idea on how to export html table data as .csv or write to txt file with separated comma and also get the filename of link from every table and put one line per rows each table. Please see the attached html and PNG of what it looks like. ... (7 Replies)
Discussion started by: lxdorney
7 Replies

3. UNIX for Dummies Questions & Answers

Convert Txt file to HTML table and email

Hi all I need help converting a text file into a html table in bash and I need to email this table. The text file looks like the below. Two columns with multiple rows. Top row being header. Application Name Application Status Application 1 Open Application 2 ... (2 Replies)
Discussion started by: hitmanjd
2 Replies

4. Shell Programming and Scripting

Input data of a file from perl into HTML table

Hi , I need an help in perl scripting. I have an perl script written and i have an for loop in that ,where as it writes some data to a file and it has details like below. cat out.txt This is the first line this is the second line. .....Now, this file needs to be send in mail in HTML... (2 Replies)
Discussion started by: scott_cog
2 Replies

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

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

7. Shell Programming and Scripting

Convert shell script output txt file to html table

Hi, I have script which generates the output as below: Jobname Date Time Status abc 12/9/11 17:00 Completed xyz 13/9/11 21:00 Running I have the output as a text file. I need to convert it into a HTML Table and sent it thru email ... (6 Replies)
Discussion started by: a12ka4
6 Replies

8. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

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

10. UNIX for Dummies Questions & Answers

How do I extract text only from html file without HTML tag

I have a html file called myfile. If I simply put "cat myfile.html" in UNIX, it shows all the html tags like <a href=r/26><img src="http://www>. But I want to extract only text part. Same problem happens in "type" command in MS-DOS. I know you can do it by opening it in Internet Explorer,... (4 Replies)
Discussion started by: los111
4 Replies
Login or Register to Ask a Question