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