更新时间:2023-12-01 14:21:10
使用awk
似乎更容易.将文本文件加载到关联数组的键中.然后读取CSV文件,并测试数组中是否包含IP字段.
This seems like it would be much easier to do with awk
. Load the text file into the keys of an associative array. Then read the CSV file, and test whether the IP field is contained in the array.
awk -i inplace -F, -v OFS=, '
NR==FNR { a[$0]++; next } # Put lines from list.txt into array
a[$8] { print $0 "SUSPICIOUS" } # Test if IP in current row is in array
{ print }' inplace=0 list.txt inplace=1 *.csv # Otherwise print row normally
这使用GNU awk的inplace扩展名,因此它可以将结果写回到输入文件中.
This uses the inplace extension of GNU awk so it can write the result back to the input file.