使用awk打印文件的重复部分

使用awk打印文件的重复部分,awk,tex,Awk,Tex,我想浏览一下这个文件: \chapter{CHAPTER} TEXT \e h454 \e \e 454 \e \begin{figure} \NOTE{figure} \centering \includegraphics[width=0.49\textwidth]{f.pdf} \caption{\NOTEB{The concept}} \label{fig} \end{figure} SOME TEXT \e 454 \e SOME TEXT \

我想浏览一下这个文件:

\chapter{CHAPTER}

TEXT   
\e
h454
\e    
\e
454
\e    
\begin{figure}
\NOTE{figure}
\centering
\includegraphics[width=0.49\textwidth]{f.pdf}
\caption{\NOTEB{The concept}}
\label{fig}
\end{figure}

SOME TEXT    
\e
454
\e    
SOME TEXT

\begin{figure}
\NOTE{figure}
\centering
\includegraphics[width=0.49\textwidth]{f.pdf}
\caption{\NOTEB{The concept}}
\label{fig}
\end{figure}

\chapter{CHAPTER}

SOME TEXT
并打印一些部分:

awk '/\\begin\{figure\}/,/\\end\{figure\}/' file.tex
awk '/\\e/,/\\e/' file.tex
awk '/\chapter/' file.tex
但是,所有这些文件都将按照输入文件中的顺序存储在一个文件中。因此,所需的输出是(空行无关紧要):


如何连接这些命令并使其遵循输入文件的顺序?

请尝试以下操作

awk '
/\\label/{
  next
}
/\\begin\{figure\}|\\beq/{
  found=1
}
found;
/\\end\{figure\}|\\eeq/{
  found=""
}
/chapter/
' Input_file

因为我在手机上写了这篇文章,我还没有测试过它,请随意评论任何建议。

我建议使用
sed
来完成这项工作。您已经在使用它的语法。到目前为止您尝试了什么?请如何使用sed。我只写单独的命令,不知道如何继续。如何从文件中删除起始行\标签?最后我试着写:
|'/^\\label/'
(我的意思是我将您的最后一行编辑为
'|'!/^\\label/'Input_file
)@Archie,请立即尝试我的编辑,让我知道这是否有帮助?
awk '
/\\label/{
  next
}
/\\begin\{figure\}|\\beq/{
  found=1
}
found;
/\\end\{figure\}|\\eeq/{
  found=""
}
/chapter/
' Input_file