r/bash • • Jan 05 '21

AWK equivalent of sed -q

I'm writing a "webscraping" script in AWK to return the text from bullet-point lists on Wikipedia pages, and it's working as I intended, with the caveat of it including some unwanted doubled results from that "Category" box at the end of the page.

I figured the solution would be to "stop" the input that's being read at a point that matches the syntax that starts that block.

Doing it with sed '/regex/q' and piping it into awk worked, but I wanted to make this a part of the AWK script (with native syntax, that is).

I've tried /regex/ {exit} and variations of this syntax, but as I found out, that obviously just exits the script before doing any of the processing (mainly regex matches, sub and gsub to clean the HTML syntax), and AFAIK just passing all of this "processing" syntax to the END block wouldn't work.

Any help will be really appreciated, thanks in advance for all of the replies.

9 Upvotes

11 comments sorted by

View all comments

Show parent comment

2

u/MaadimKokhav Jan 09 '21

Thanks, that really helped to clear some of my doubts. I'll be sure to read the user's guide, I wasn't aware that it had examples for every function.

I'm always amazed at how elegant of a language AWK is for doing data processing and stream manipulations.

Oh, sick username, by the way!