Shell Script AWK Regular Expression – Match Multiple Regular Expressions from a Single File Using AWK

awkregular expressionshell-script

I'm trying to parse a HTML file using shell scripting.

There are 4 different regular expressions that i need to catch: name= , age= , class= , marks=.

Using

grep "name=\|age=\|class=\|marks=" student.txt

I'm able to get the required lines, but along with these matching lines I also need to print the second line from each match which contains the score.

Referring to the question: Print Matching line and nth line from the matched line.

I modified the code to:

awk '/name=\|age=\|class=\|marks=/{nr[NR]; nr[NR+2]}; NR in nr' student.txt

But this does not seem to work. How do I search for multiple regular expressions in the same awk command?

Best Answer

Try with:

awk '/foo/||/bar/' Input.txt
Related Question