繁体   English   中英

在UNIX Shell脚本中再次比较csv文件中的字符串和查找文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM