使用Unix命令比较两个文件并查找常用项

时间:2015-03-09 10:01:25

标签: unix awk rtf text-processing

我有两个文件,其中包含有关IP地址的一些信息。我需要比较这些文件,然后我需要创建一个新文件,只包含New.txt和Old.txt共有的项目。我需要将其作为批处理运行,这就是为什么我需要知道unix命令来自动执行此过程。

然而,重要的事实是,虽然两个文件中可能有相同的描述,但起始编号可能不同。

例如: New.txt

\subsubsection {Summary of security vulnerabilities found on the host with IP address 123.123.123.123}
\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 & Oracle GlassFish Server Multiple Vulnerabilities (July 2014 CPU) & \href{http://www.nessus.org/u?7de2f8eb}{$\Rightarrow$}   \\ \hline
     2  & \cellcolor{Red}High & Oracle GlassFish Server Unspecified Vulnerability (January 2015 CPU) & \href{http://www.nessus.org/u?c02f1515}{$\Rightarrow$}   \\ \hline
     3  & \cellcolor{BurntOrange}Medium & Apache HTTP Server httpOnly Cookie Information Disclosure  & \href{http://fd.the-wildcat.de/apache\_e36a9cf46c.php}{$\Rightarrow$}  \\ \hline
     4  & \cellcolor{BurntOrange}Medium & HTTP TRACE / TRACK Methods Allowed  & \href{http://www.cgisecurity.com/whitehat-mirror/WH-WhitePaper\_XST\_ebook.pdf}{$\Rightarrow$}  \\ \hline
     5  & \cellcolor{BurntOrange}Medium & Oracle GlassFish Server 3.0.1 / 3.1.2 / Enterprise 2.1.1 DoS  & \href{http://www.nessus.org/u?1cef09be}{$\Rightarrow$}  \\ \hline
     6  & \cellcolor{BurntOrange}Medium & Oracle GlassFish Server Multiple Vulnerabilities (October 2013 CPU)  & \href{http://www.nessus.org/u?4ea424bc}{$\Rightarrow$}  \\ \hline
     7  & \cellcolor{BurntOrange}Medium & SSL Version 2 and 3 Protocol Detection  & \href{http://www.schneier.com/paper-ssl.pdf}{$\Rightarrow$}  \\ \hline
     8  & \cellcolor{BurntOrange}Medium & SSLv3 Padding Oracle On Downgraded Legacy Encryption Vulnerability (POODLE)  & \href{https://www.imperialviolet.org/2014/10/14/poodle.html}{$\Rightarrow$}  \\ \hline
     9  & \cellcolor{SkyBlue}Low & SSL RC4 Cipher Suites Supported  & \href{http://www.nessus.org/u?217a3666}{$\Rightarrow$}  \\ \hline
    10  & \cellcolor{SkyBlue}Low & Web Server Uses Basic Authentication Without HTTPS  & \href{http://www.tenable.com/plugins/index.php?view=single&id=34850}{$\Rightarrow$}  \\ \hline
\end{longtable}
\end{center}

Old.txt

\subsubsection {Summary of security vulnerabilities found on the host with IP address 123.123.123.123}
\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 & Oracle GlassFish Server Multiple Vulnerabilities (July 2014 CPU) & \href{http://www.nessus.org/u?7de2f8eb}{$\Rightarrow$}   \\ \hline
     2  & \cellcolor{BurntOrange}Medium & Apache HTTP Server httpOnly Cookie Information Disclosure  & \href{http://fd.the-wildcat.de/apache\_e36a9cf46c.php}{$\Rightarrow$}  \\ \hline
     3  & \celcolor{BurntOrange}Medium & HTTP TRACE / TRACK Methods Allowed  & \href{http://www.cgisecurity.com/whitehat-mirror/WH-WhitePaper\_XST\_ebook.pdf}{$\Rightarrow$}  \\ \hline
     4  & \cellcolor{BurntOrange}Medium & Oracle GlassFish Server 3.0.1 / 3.1.2 / Enterprise 2.1.1 DoS  & \href{http://www.nessus.org/u?1cef09be}{$\Rightarrow$}  \\ \hline
     5  & \cellcolor{BurntOrange}Medium & Oracle GlassFish Server Multiple Vulnerabilities (October 2013 CPU)  & \href{http://www.nessus.org/u?4ea424bc}{$\Rightarrow$}  \\ \hline
     6  & \cellcolor{BurntOrange}Medium & PHP expose\_php Information Disclosure  & \href{http://www.0php.com/php\_easter\_egg.php}{$\Rightarrow$}  \\ \hline         7 & \cellcolor{SkyBlue}Low & SSL RC4 Cipher Suites Supported  & \href{http://www.nessus.org/u?217a3666}{$\Rightarrow$}  \\ \hline
     8  & \cellcolor{SkyBlue}Low & Web Server Uses Basic Authentication Without HTTPS  & \href{http://www.tenable.com/plugins/index.php?view=single&id=34850}{$\Rightarrow$}  \\ \hline
     9  & \cellcolor{SkyBlue}Low & Web Server Uses Plain Text Authentication Forms  & \href{http://www.tenable.com/plugins/index.php?view=single&id=26194}{$\Rightarrow$}  \\ \hline
\end{longtable}
\end{center}

最后比较文件并仅打印常用项目 compare.txt

\subsubsection {Summary of security vulnerabilities found on the host with IP address 123.123.123.123}
\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 & Oracle GlassFish Server Multiple Vulnerabilities (July 2014 CPU) & \href{http://www.nessus.org/u?7de2f8eb}{$\Rightarrow$}   \\ \hline
     2  & \cellcolor{BurntOrange}Medium & Apache HTTP Server httpOnly Cookie Information Disclosure  & \href{http://fd.the-wildcat.de/apache\_e36a9cf46c.php}{$\Rightarrow$}  \\ \hline
     3  & \cellcolor{BurntOrange}Medium & HTTP TRACE / TRACK Methods Allowed  & \href{http://www.cgisecurity.com/whitehat-mirror/WH-WhitePaper\_XST\_ebook.pdf}{$\Rightarrow$}  \\ \hline
     4  & \cellcolor{BurntOrange}Medium & Oracle GlassFish Server 3.0.1 / 3.1.2 / Enterprise 2.1.1 DoS  & \href{http://www.nessus.org/u?1cef09be}{$\Rightarrow$}  \\ \hline
     5  & \cellcolor{BurntOrange}Medium & Oracle GlassFish Server Multiple Vulnerabilities (October 2013 CPU)  & \href{http://www.nessus.org/u?4ea424bc}{$\Rightarrow$}  \\ \hline
     6  & \cellcolor{SkyBlue}Low & SSL RC4 Cipher Suites Supported  & \href{http://www.nessus.org/u?217a3666}{$\Rightarrow$}  \\ \hline
    7   & \cellcolor{SkyBlue}Low & Web Server Uses Basic Authentication Without HTTPS  & \href{http://www.tenable.com/plugins/index.php?view=single&id=34850}{$\Rightarrow$}  \\ \hline
\end{longtable}
\end{center}

1 个答案:

答案 0 :(得分:0)

comm -12 Old.txt New.txt > common.txt

相关问题