sed found lines with set articles (a, an, the)

Viewed 31

I should find lines with articles i set by myself. Search among first 10 lines.

sed -n '/the/p' file.txt | sed -n '/ a /p' file.txt 

will show only output from the last command. Also

sed -n '1,10 /the/p' file

or

sed -n 1,10p '/the/p' file

dont work, i found usage of range only with patterns like

[range]/s/pattern/pattern/p

How can i combine several conditions and range of lines?

Example of file:

For the first time since early February
the top three films at the weekend 
box office were all new releases
and leading the way was
Fox's Bohemian Rhapsody
with a $50 million
chart-topping performance
well above expectations.
That said, the weekend isn't all about
new releases as the holdovers

Output should be:

 For the first time since early February
 the top three films at the weekend
 and leading the way was
 with a $50 million
 That said, the weekend isn't all about
 new releases as the holdovers
1 Answers
  • To get lines containing the

    sed -n '1,10{/\<the\>/p}' file
    
  • To get lines containing the or a or an

    sed -n '1,10{/\<\(the\|a\|an\)\>/p}' file
    
Related