簡體   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