![](/img/trans.png)
[英]compare a set of strings from one csv file in another csv file using Unix Shell script
[英]Compare a string from a csv file againt a lookup file in unix shell scripting
我是unix脚本的新手。 我有一个要求,我需要对照另一个csv文件中的一组字符串检查一个csv文件中的字符串。 我的file1将具有如下所示的值, file1
task desc
1 network error in there in line one.
2 data error is there in line three.
3 connection is missing from device.
4 new error is there
并且file2
将具有标准查找数据file2
Network error
data error
connection is
file2
是静态的,而我的file1
每天都在更改。 我的要求是检查file1
每一行,并对照file2
中的字符串进行检查。 如果file1
有任何新的错误条目,则需要将整行写入名为file3
的新文件中。 从日志文件检查这种日常标准错误并报告新错误。 例如,从上面的示例中,输出file3
需要如下所示。
文件3
4 new error is there
tail + grep解决方案:
tail -n +2 file1 | grep -ivf file2 > file3
> cat file3
4 new error is there
tail -n +2 file1
-输出的最后部分file1
从第二行开始 grep选项:
-f
从文件获取模式
-i
区分大小写的匹配
-v
反转匹配感,选择不匹配的行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.