如何扫描条件匹配字符串并在匹配时循环

How to Scan for conditional matching string and loop if matched

我有 2 个文件,大的和小的带有 ';'分隔。

old_file
    Apple;aaa@abc.com
    Banana;bbb@abc.com
    carrot;ccc@abc.com


new File  
Banana;new@abc.com

我正在创建一个 shell 脚本来检查新文件数据并发送电子邮件,然后扫描剩余的 大文件中的数据不匹配并分别发送电子邮件。(对于匹配的值应该是新的电子邮件)

我的代码


#Variables
name_old=`awk -F ";" '{print } {$temp}`; 
email_old=`awk -F ";" '{print } {$temp}`;
name_new=`cat 'smallfile' | awk -F ";" '{print }'`;
email_new=`cat 'smallfile' | awk -F ";" '{print }'`;


///
if #grep -wq $name_new <<< $name_old
[[ "$name_new" == "$name_old" ]]
then
echo "store the matched value email in a variable"
else
echo "store the unmatched value email in a variable"
fi  



sample Output can be stored in a variable.
aaa@abc.com  
new@abc.com--->matching record so updated email  
ccc@abc.com

如果有任何问题,有人可以查看和更新​​吗? 我是 shell 脚本的新手,但正在尝试 :)

awk 是更合适的工具。

awk 'BEGIN {FS=OFS=";"} NR==FNR {map[]=; next}  in map {=map[]} 1' newfile oldfile

Apple;aaa@abc.com
Banana;new@abc.com
carrot;ccc@abc.com