簡體   English   中英

如何在Linux中比較兩個乳膠文件?

[英]How to compare two latex files in linux?

我需要將New.tex http://pastebin.com/PCafGYwG與Old.tex http://pastebin.com/jRU8rhhV進行比較,如果相同IP中的兩個文檔中都存在相同漏洞,則需要輸出。

例如:兩個文件的IP地址均為10.1.2.3。

新特克斯

 \subsection {Summary of security vulnerabilities found on the host with IP address 10.1.2.3}
\begin{center}
\begin{longtable}{|p{0.2in}|p{0.5in}|p{4in}|p{0.4in}|} \hline
\textit{\textbf{No}} &\textit{\textbf{Severity level}} & \textit{\textbf{Vulnerability name}} & \textit{\textbf{More}} \\ \hline
     1  & \cellcolor{Red}High& DNS Server Cache Snooping Remote Information Disclosure  & \href{http://www.rootsecure.net/content/downloads/pdf/dns\_cache\_snooping.pdf}{$\Rightarrow$}  \\ \hline
     2  & \cellcolor{BurntOrange}Medium & SSL Certificate with Wrong Hostname  & \href{http://www.tenable.com/plugins/index.php?view=single&id=45411}{$\Rightarrow$}  \\ \hline
     3  & \cellcolor{BurntOrange}Medium & SSL Self-Signed Certificate  & \href{http://www.tenable.com/plugins/index.php?view=single&id=57582}{$\Rightarrow$}  \\ \hline
     4  & \cellcolor{SkyBlue}Low & SSL RC4 Cipher Suites Supported  & \href{http://www.nessus.org/u?217a3666}{$\Rightarrow$}  \\
\end{longtable}
\end{center}
.............
.....................
...

舊文本

.............
.......
......................
 \subsection {Summary of security vulnerabilities found on the host with IP address 10.1.2.3}
\begin{center}
\begin{longtable}{|p{0.2in}|p{0.5in}|p{4in}|p{0.4in}|} \hline
\textit{\textbf{No}} &\textit{\textbf{Severity level}} & \textit{\textbf{Vulnerability name}} & \textit{\textbf{More}} \\ \hline
     1  & \cellcolor{BurntOrange}Medium & DNS Server Cache Snooping Remote Information Disclosure  & \href{http://www.rootsecure.net/content/downloads/pdf/dns\_cache\_snooping.pdf}{$\Rightarrow$}  \\ \hline
     2  & \cellcolor{BurntOrange}Medium & SSL Certificate Cannot Be Trusted  & \href{http://www.tenable.com/plugins/index.php?view=single&id=51192}{$\Rightarrow$}  \\ \hline
     3  & \cellcolor{BurntOrange}Medium & SSL Certificate with Wrong Hostname  & \href{http://www.tenable.com/plugins/index.php?view=single&id=45411}{$\Rightarrow$}  \\ \hline
     4  & \cellcolor{BurntOrange}Medium & SSL Self-Signed Certificate  & \href{http://www.tenable.com/plugins/index.php?view=single&id=57582}{$\Rightarrow$}  \\ \hline
\end{longtable}
\end{center}
..............
.......
...........

在這種情況下,

兩者都具有漏洞=“ DNS服務器緩存偵聽遠程信息披露”“具有錯誤主機名的SSL證書”“ SSL自簽名證書”

我需要輸出

僅漏洞摘要如下

\subsection {Summary of security vulnerabilities found on the host with IP address 10.1.2.3}
\begin{center}
\begin{longtable}{|p{0.2in}|p{0.5in}|p{4in}|p{0.4in}|} \hline
\textit{\textbf{No}} &\textit{\textbf{Severity level}} & \textit{\textbf{Vulnerability name}} & \textit{\textbf{More}} \\ \hline
     1  & \cellcolor{Red}Medium & DNS Server Cache Snooping Remote Information Disclosure  & \href{http://www.rootsecure.net/content/downloads/pdf/dns\_cache\_snooping.pdf}{$\Rightarrow$}  \\ \hline
     2  & \cellcolor{BurntOrange}Medium & SSL Certificate with Wrong Hostname  & \href{http://www.tenable.com/plugins/index.php?view=single&id=45411}{$\Rightarrow$}  \\ \hline
     3  & \cellcolor{BurntOrange}Medium & SSL Self-Signed Certificate  & \href{http://www.tenable.com/plugins/index.php?view=single&id=57582}{$\Rightarrow$}  \\ \hline
\end{longtable}
\end{center}

如何在Linux上使用bash腳本,awk,sed或任何其他方法來實現此目的?

您可以使用diff命令或diffuse GUI工具比較兩個文件:

diff Old.tex New.tex

要么

diffuse Old.tex New.tex

為了進行更深入的分析,我建議編寫一個簡短的python(或perl)腳本,在其中讀取兩個文件,找到您感興趣的行,進行比較,並進行所需的替換。

最簡單的方法是在第一行中查找要搜索的唯一文本,然后使用grep定位該行,並添加-A8來捕獲接下來的8行上下文。 在您的情況下,可能會執行以下操作:

grep -A8 {Summary\ of\ security\ vulnerabilities filename

假設單詞組合對於漏洞行是唯一的,那么您將獲得上面指示的行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM