sed нашел строки с множеством статей (a, an, the) - PullRequest
0 голосов
/ 04 ноября 2018

Я должен найти строки со статьями, которые я сам установил. Поиск среди первых 10 строк.

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

покажет только результат последней команды. Также

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

или

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

не работает, я нашел использование диапазона только с такими шаблонами, как

[range]/s/pattern/pattern/p

Как мне объединить несколько условий и диапазон линий?

Пример файла:

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

Вывод должен быть:

 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 Ответ

0 голосов
/ 04 ноября 2018
  • Для получения строк, содержащих the

    sed -n '1,10{/\<the\>/p}' file
    
  • Для получения строк, содержащих the или a или an

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