首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何比较linux中的两个胶乳文件?

如何比较linux中的两个胶乳文件?
EN

Stack Overflow用户
提问于 2014-07-28 08:28:32
回答 2查看 238关注 0票数 1

我需要将New.tex http://pastebin.com/PCafGYwG与Old.tex http://pastebin.com/jRU8rhhV进行比较,如果相同IP中的两个文档中存在相同的漏洞,则需要获得输出。

两个文件的IP地址都是10.1.2.3。

New.tex

代码语言:javascript
复制
 \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}
.............
.....................
...

Old.tex

代码语言:javascript
复制
.............
.......
......................
 \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自签名证书“

我需要输出

只有下面的漏洞摘要

代码语言:javascript
复制
\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或任何其他方法来实现这一点?

EN

回答 2

Stack Overflow用户

发布于 2015-05-27 19:55:26

您可以使用diff命令或diffuse GUI工具比较两个文件:

代码语言:javascript
复制
diff Old.tex New.tex

代码语言:javascript
复制
diffuse Old.tex New.tex

为了进行更深入的分析,我建议编写一个简短的python (或perl)脚本,在脚本中读取两个文件,找到您感兴趣的行,比较它们,并进行所需的替换。

票数 0
EN

Stack Overflow用户

发布于 2014-07-28 08:39:37

最简单的方法是在第一行中找到要搜索的唯一文本,然后使用grep定位该行,并添加-A8以捕获接下来的8行上下文。在您的情况下,可能会发生以下情况:

代码语言:javascript
复制
grep -A8 {Summary\ of\ security\ vulnerabilities filename

假设单词的组合对于漏洞行是唯一的,那么您将得到您希望得到的上面的行。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24991182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档