用awk打印文件的重复部分
printing repeated parts of file with awk
我想浏览一下这个文件:
\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
但全部放入一个文件中,并按照输入文件中的顺序排列。因此,所需的输出是(空行无关紧要):
\chapter{CHAPTER}
\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}
\e
454
\e
\begin{figure}
\NOTE{figure}
\centering
\includegraphics[width=0.49\textwidth]{f.pdf}
\caption{\NOTEB{The concept}}
\label{fig}
\end{figure}
\chapter{CHAPTER}
如何连接这些命令并使其遵循输入文件的顺序?
能否请您尝试以下。
awk '
/\label/{
next
}
/\begin\{figure\}|\beq/{
found=1
}
found;
/\end\{figure\}|\eeq/{
found=""
}
/chapter/
' Input_file
因为我把这个写在我的手机上,我还没有测试过,请随时评论任何建议。
我想浏览一下这个文件:
\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
但全部放入一个文件中,并按照输入文件中的顺序排列。因此,所需的输出是(空行无关紧要):
\chapter{CHAPTER}
\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}
\e
454
\e
\begin{figure}
\NOTE{figure}
\centering
\includegraphics[width=0.49\textwidth]{f.pdf}
\caption{\NOTEB{The concept}}
\label{fig}
\end{figure}
\chapter{CHAPTER}
如何连接这些命令并使其遵循输入文件的顺序?
能否请您尝试以下。
awk '
/\label/{
next
}
/\begin\{figure\}|\beq/{
found=1
}
found;
/\end\{figure\}|\eeq/{
found=""
}
/chapter/
' Input_file
因为我把这个写在我的手机上,我还没有测试过,请随时评论任何建议。