Sponsored Content
Top Forums UNIX for Dummies Questions & Answers extract data from html tables Post 302177113 by bakunin on Thursday 20th of March 2008 05:04:41 AM
Old 03-20-2008
Quote:
the only problem with your solution is that most of the <tr> tags are across multiple lines in my html page. ie the tag may be opened on line 7 and then closed on line 20.
Well, i told you that - in absence of any example - i had to make some assumptions. Here is a new version which will work on tags ranging over several lines. It will still not catch the case of several "<tr>...</tr>" pairs on one line, though.

Code:
sed -n '/<tr>/,/<\/tr> {
           s/.*<tr>//
           s/<\/tr>.*//
           p
           }' /path/to/your/file

How this works: the "-n" clause will stop sed from printing every line it has read, so if you delete the script it would print just nothing. This is to (implicitly) throw out all the lines which are NOT in the specified range.

Everything between the curly braces is executed only when inside the range specified on line 1. As you can see the last command inside the curly braces is a "p", which will print everything inside this range. If you delete the two "s/...."-commands it would print something this:

Code:
something....<tr> content of the tr-tag
some more content
even more content</tr> something else....

As you can see the bold parts should be deleted as they are not part of what you want. The two "s/..."-commands (s=substitute) take care of that along with the tags themselves. At last the p(rint)-command outputs the result of all the trimming.

One more word, though: You got a second answer from me because i appreciated that you were doing genuine research on your own. You almost forfeited this answer because of this:

Quote:
[...]withough having to waste time making an example table
You might notice i have "wasted time" not only writing a script but even wasted more time explaining how it works in the hope of not only solving the problem at hand but enhancing your understanding at the same time. On top of that i "wasted some more time" to write a script in my first post which nobody is going to need because it was based on faulty assumptions. Assumptions which might not have been faulty at all would i have been able to work from an example created by "wasting time".

I am even now "wasting some more time" to explain to you why you might sometimes get no answer at all or some answer you can't use. Go figure.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies

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

3. Shell Programming and Scripting

SED to extract HTML text data, not quite right!

I am attempting to extract weather data from the following website, but for the Victoria area only: Text Forecasts - Environment Canada I use this: sed -n "/Greater Victoria./,/Fraser Valley./p" But that phrasing does not sometimes get it all and think perhaps the website has more... (2 Replies)
Discussion started by: lagagnon
2 Replies

4. AIX

Extract data from DB2 tables and FTP it to outside company's firewall

Please help me in creating the script in AIX. requirement is; The new component's main function is to extract the data from DB2 tables and company's firewall directly. The component function needs to check the timestamp in the DB2 tables ((CREDAT and CRETIM) with the requested timestamp and... (1 Reply)
Discussion started by: priyanka3006
1 Replies

5. Shell Programming and Scripting

extract data with awk from html files

Hello everyone, I'm new to this forum and i am new as a shell scripter. my problem is to have html files in a directory and I would like to extract from these some data that lies between two different lines Here's my situation <td align="default"> oxidizability (mg / l): data_to_extract... (6 Replies)
Discussion started by: sbobotex
6 Replies

6. Shell Programming and Scripting

awk to create two HTML Tables

I am working on awk script to generate an HTML format output. With input file as below I am able to generate a HTML file however I want to saperate spare devices in a different table than rest of the devices and which has only Bunch ID, RAW Size and "Bunch Spare" status columns. INPUT File : ... (2 Replies)
Discussion started by: dynamax
2 Replies

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

8. Shell Programming and Scripting

awk -- Extract data from html within multiple tags as reference

Hi, I'm trying to get some data from an html file, but the problem is before it can extract the information I have multiple patterns that need to be passed through. https://www.unix.com/shell-programming-scripting/150711-extract-data-awk-html-files.html Is a similar problem. The only... (5 Replies)
Discussion started by: counfhou
5 Replies

9. Shell Programming and Scripting

Splitting csv into 3 tables in html file

I have the data in csv in 3 tables. how can I output the same into 3 tables in html.also how can I set the width. tried multiple options . attached is the format. #!/bin/ksh awk 'BEGIN{ FS="," print "<HTML><BODY><TABLE border = '1' cellpadding=10 width=100>" print... (7 Replies)
Discussion started by: archana25
7 Replies

10. UNIX for Beginners Questions & Answers

Extract the tables from html

Hi I have a script which extracts the table from HTML and convert it into .csv. But the problem in the script is if we have 2 tables in HTMl . it takes only the first table. Please help me what changes i need to do in the script to make it read the complete HTML page. Script is as below: ... (10 Replies)
Discussion started by: deepti01
10 Replies
ARITHMETIC(6)							   Games Manual 						     ARITHMETIC(6)

NAME
arithmetic - provide drill in number facts SYNOPSIS
/usr/games/arithmetic [ +-x/ ] [ range ] DESCRIPTION
Arithmetic types out simple arithmetic problems, and waits for an answer to be typed in. If the answer is correct, it types back "Right!", and a new problem. If the answer is wrong, it replies "What?", and waits for another answer. Every twenty problems, it publishes statis- tics on correctness and the time required to answer. To quit the program, type an interrupt (delete). The first optional argument determines the kind of problem to be generated; +-x/ respectively cause addition, subtraction, multiplication, and division problems to be generated. One or more characters can be given; if more than one is given, the different types of problems will be mixed in random order; default is +- Range is a decimal number; all addends, subtrahends, differences, multiplicands, divisors, and quotients will be less than or equal to the value of range. Default range is 10. At the start, all numbers less than or equal to range are equally likely to appear. If the respondent makes a mistake, the numbers in the problem which was missed become more likely to reappear. As a matter of educational philosophy, the program will not give correct answers, since the learner should, in principle, be able to calcu- late them. Thus the program is intended to provide drill for someone just past the first learning stage, not to teach number facts de novo. For almost all users, the relevant statistic should be time per problem, not percent correct. ARITHMETIC(6)
All times are GMT -4. The time now is 04:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy