比较 bash、diff 和相同值中的三个数组 [英] Compare three arrays in bash, diff and identical values

查看:20
本文介绍了比较 bash、diff 和相同值中的三个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是指已回答的问题:bash 中两个数组的比较/差异

This question refers to the answered question: Compare/Difference of two arrays in bash

让我们取两个数组:

Array1=( "key1" "key2" "key3" "key4" "key5" "key6" "key7" "key8" "key9" "key10" "key13" )
Array2=( "key1" "key2" "key3" "key4" "key5" "key6" "key11" "key12" "key13" )

数组之间的对称差异:

Array3=(`echo ${Array1[@]} ${Array2[@]} | tr ' ' '
' | sort | uniq -u `)

Array3 值:

echo $Array3
key10
key11
key12
key7
key8
key9

仅在 Array1 中的值:

Values only in Array1:

echo ${Array1[@]} ${Array3[@]} | tr ' ' '
' | sort | uniq -D | uniq
key10
key7
key8
key9

仅在 Array2 中的值

Values only in Array2

echo ${Array2[@]} ${Array3[@]} | tr ' ' '
' | sort | uniq -D | uniq
key11
key12

我的问题,我们如何获得 Array1 & 中的值?Array2 但不在 Array3 中(相同)?预期结果:

My question, how can we get values that are in Array1 & Array2 but not in Array3 (identical)? Expected result:

key1
key13
key2
key3
key4
key5
key6

感谢您的帮助.

推荐答案

经过几次测试OK,看来我正在寻找的答案只是:

OK after few test, it seems the answer I was looking for was just:

echo ${Array1[@]} ${Array2[@]} | tr ' ' '
' | sort | uniq -D | uniq
key1
key13
key2
key3
key4
key5
key6

这篇关于比较 bash、diff 和相同值中的三个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆