Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

awk - output first occurrence of <table>...</table>

5 views
Skip to first unread message

gismo82

unread,
Nov 22, 2009, 7:11:40 AM11/22/09
to
Hi...

i've tried to print only <table>...</table> part out of an html-
document.

Example:
<html>
<body>
...
...
...
<table>
<tr>
<td>test1</td>
</tr>
</table>
...
...
<table>
<tr>
<td>test2</td>
</tr>
</table>
...
...
...
</body>
</html>

Now I've tried to print the first occurrence of <table>...</table>:

<table>
<tr>
<td>test1</td>
</tr>
</table>

Can anyone help me? I'm a Beginner in AWK.


Kind regards

Andreas

Ed Morton

unread,
Nov 22, 2009, 7:55:18 AM11/22/09
to

If the delimiters are really on their own lines:

awk '/<table>/{f=1} f /<[/]table>/{exit}' file

Ed.

Ed Morton

unread,
Nov 22, 2009, 8:01:30 AM11/22/09
to

missed the semicolon:

gismo82

unread,
Nov 22, 2009, 3:53:39 PM11/22/09
to
Hi Ed...

thank you for your experience.

By the way...I'm searching for an Book about AWK / sed. Can you tell
me a favourite one?


Kind regards

Andreas

Ed Morton

unread,
Nov 22, 2009, 4:38:47 PM11/22/09
to
gismo82 wrote:
> Hi Ed...
>
> thank you for your experience.
>
> By the way...I'm searching for an Book about AWK / sed. Can you tell
> me a favourite one?

Don't get a book on sed. Sed is an excellent tool for simple substitutions on a
single line. For anything else you should use awk or perl or similar so anything
you think you might need a book on sed for, you shouldn't be using sed for so
you don't need a book on it.

For awk get Effective Awk Programming, Third Edition By Arnold Robbins
http://www.oreilly.com/catalog/awkprog3/.

Ed.

Barrie

unread,
Nov 23, 2009, 10:00:16 PM11/23/09
to

There are many resources online also for learning awk, here is one.
http://www.gnu.org/software/gawk/manual/gawk.html#dir You can dl the
file: http://www.gnu.org/software/gawk/manual/

Barrie

Ed Morton

unread,
Nov 25, 2009, 8:52:19 AM11/25/09
to

Yeah, but then the author won't make any money off the enormous amount of work
he put into it and maybe he won't bother to keep maintaining the online version,
or the tool itself, or writing the next version of the book, etc. so it'd be
nice if people actually bought the book:

Effective Awk Programming, Third Edition By Arnold Robbins
http://www.oreilly.com/catalog/awkprog3/

and just used the on-line version as a reference when convenient.

Ed.

0 new messages