一种方式。
内容script.awk
:
BEGIN {
## Split line with a doble quote surrounded with spaces.
FS = "[ ]*\"[ ]*"
}
## File with words, save them in a hash.
FNR == NR {
words[ $2 ] = 1;
next;
}
## File with multiple columns.
FNR < NR {
## Omit line if eigth field has no interesting value or is first line of
## the file (header).
if ($8 == "N/A" || FNR == 1) {
print $0
next
}
## Split interested field with commas. Traverse it searching for a
## word saved from first file. Print line only if not found.
## Change due to an error pointed out in comments.
##--> split($8, array, /[ ]*,[ ]*/)
##--> for (i = 1; i <= length(array); i++) {
len = split($8, array, /[ ]*,[ ]*/)
for (i = 1; i <= len; i++) {
## END change.
if (array[ i ] in words) {
found = 1
break
}
}
if (! found) {
print $0
}
found = 0
}
假设File1.csv
和File2.csv
已经托尔的答案的评论提供的内容(我建议加上这些信息的问题),运行像脚本:
awk -f script.awk File2.csv File1.csv
With following output:
"DNSName","IP","OS","CVE","Name","Risk"
"ex.example.com","1.2.3.4","Linux","N/A","HTTP 1.1 Protocol Detected","Information"
"ex.example.com","1.2.3.4","Linux","CVE-2011-3048","LibPNG Memory Corruption Vulnerability (20120329) - RHEL5","High"
"ex.example.com","1.2.3.4","Linux","CVE-2012-2141","Net-SNMP Denial of Service (Zero-Day) - RHEL5","Medium"
"ex.example.com","1.2.3.4","Linux","N/A","Web Application index.php?s=-badrow Detected","High"
"ex.example.com","1.2.3.4","Linux","CVE-1999-0662","Apache HTTPD Server Version Out Of Date","High"
"ex.example.com","1.2.3.4","Linux","CVE-1999-0662","PHP Unsupported Version Detected","High"
"ex.example.com","1.2.3.4","Linux","N/A","HBSS Common Management Agent - UNIX/Linux","High"
所以我尝试了你的方法,我仍然留下了与'grep -v -F -f File2.csv File1.csv> File3.csv' – eloscurosecreto 2012-07-13 17:27:59
相同的结果然后你需要向我们展示'File1.csv的确切样本'和'File2.csv'。以上工作与你迄今为止提供的内容一致。 – Thor 2012-07-13 17:42:35
以下是指向这些文件的链接: - [File1.csv](https://www.dropbox.com/s/ryrk0ofenzzmfuj/File1.csv) - [Files2.csv](https:// www。 dropbox.com/s/o59t2lfobgjugd5/File2.csv) 我希望这有助于。谢谢! – eloscurosecreto 2012-07-13 17:58:50