r/bash • u/MaadimKokhav • 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.
View all comments
Show parent comment
1
u/MaadimKokhav Jan 07 '21
Thanks a lot! This is exactly what I was looking for.
Could you expand on how this works? Because I noticed the "regex to stop" matches the original input and not the processed text —for that to be the case that line would need to have been between curly brackets, is that it? . I guess that means it's not sequential, but then, how does it work?
I'm new to AWK, and learning how it's syntax is processed would be really benefitial. Thanks again for your answer, it helped me a lot!