
Я хочу сопоставить внутреннюю среду begin{question}
и ее соответствие end{question}
.
Пример данных
\section{Takayasu arteritis}
\begin{question}
{You get a patient.
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}
\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye.
So special eye diagnosis done.
Affects eye.
\end{question}
Fever of unknown origin can be used when you do not know what is causing the disease.
% Show cases in MedScape and ask class.
Aneurysms.
\subsection{Treatment}
\begin{question}
{What you should always include in Takayasu treatment?
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment.
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}
Мой ожидаемый результат:
\begin{question}
{You get a patient.
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}
или
\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye.
So special eye diagnosis done.
Affects eye.
\end{question}
или
\begin{question}
{What you should always include in Takayasu treatment?
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment.
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}
Как можно соответствовать только самой внутренней среде?
решение1
Попробуй это:
pcregrep -M '\\begin{question}(.|\n)*?\\end{question}'
Объяснение:
pcregrep
: grep с регулярными выражениями, совместимыми с Perl-M
: Разрешить шаблонам соответствовать более чем одной строке(.|\n)*?
: любой обычный символ.
или новая строка\n
, совпадающие ноль или более раз.
, в нежадном режиме?
.
Результат:
\begin{question}
{You get a patient.
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}
\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye.
So special eye diagnosis done.
Affects eye.
\end{question}
\begin{question}
{What you should always include in Takayasu treatment?
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment.
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}
решение2
Нужно ли вам, чтобы это было чистое решение на основе регулярных выражений или просто perlish?
perl -lne 'print if(/^\\begin{question}/ .. /^\\end{question}/)' file