【问题标题】:How to compare two latex files in linux?如何比较linux中的两个latex文件?
【发布时间】:2014-07-28 08:28:32
【问题描述】:

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

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

New.tex

 \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

.............
.......
......................
 \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 Server Cache Snooping Remote Information Disclosure" "SSL Certificate with Wrong Hostname" "SSL Self-Signed Certificate"

我需要输出

只有漏洞摘要如下

\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 或任何其他方法实现此目的?

【问题讨论】:

  • 我会开始做类似的事情:awk '/10.1.2.3/ {f=1} f; /\end{center}/ {f=0}' new > stuff_new 来存储一个特定的块,然后与old 文件相同。然后你可以以某种方式比较它们,尽管它们看起来很不一样。
  • 过滤规则是什么?为什么你在高中和高中之间选择中等?

标签: linux bash awk sed


【解决方案1】:

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

diff Old.tex New.tex

diffuse Old.tex New.tex

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

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 这并没有真正回答问题,如何从两个乳胶文件中获取相同的块。
    • 让我们看看我是否明白你在说什么?我的回答显示了如何从filename 获得他需要的摘要。你是说他不够聪明,不能用filename=oldfilenamefilename=newfilename 来获得2 个汇总块进行比较?
    • 简单地说,你的答案没有给出想要的输出,例如如果同一 IP 中的两个文档中存在相同的漏洞,则获取输出。 您将这个可怜的家伙发送到 tour。当钥匙变得那么小时,你不讨厌吗? :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 2015-04-12
    • 2013-01-08
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 2015-04-14
    相关资源
    最近更新 更多