【发布时间】:2015-05-10 10:42:48
【问题描述】:
我有两个文件,其中包含有关 IP 地址的一些信息。我需要比较这些文件,然后我需要创建一个新文件,其中只包含 New.txt 和 Old.txt 共有的项目。我需要将它作为批处理运行,这就是为什么我需要知道 unix 命令来自动化这个过程。
尽管如此,重要的事实是,虽然两个文件中的描述可能相同,但起始编号可能不同。
例如: 新建.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}
旧.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}
最后比较文件,只打印常见的项目 比较.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.如果结果必须包含两个文件中具有相同 IP 地址的项目,为什么还要在 compare.txt 中包含甚至没有 IP 的前 4 行和后 2 行地址?2.你想要结果中的 Old.txt 文件的完整行吗?只包含 IP 地址不是更好吗?3.“批处理文件”标签是指 Windows .BATch 文件(您可以查看标签说明)。如果您想要的不是 .BAT 文件解决方案,而是 Unix 解决方案,请删除此标签;否则请确认您需要一个 Windows .BAT 文件(并删除“unix”标签)。
标签: unix awk rtf text-processing