?删除strA中包含strB中存在的key和value,最后合并strB和strA.
strA="long=1 string=2e test=http://cnfiefish.com"
strB="string=3b"
for var in ${strA[@]}
do
key=(`echo "${var}" | awk -F '=' '{print $1}'`)
echo "key: $key"
if [[ $strB =~ $key ]]; then
strA=${strA[@]/$var/}
echo "----- $key , +++++++$var"
fi
#echo ${result}
done
echo "__________________"
echo "strB :$strB"
echo "strA :$strA"
echo "$strA $strB"
输出:
key: long
key: string
----- string , +++++++string=2e
key: test
__________________
strB :string=3b
strA :long=1 test=http://cnfiefish.com
long=1 test=http://cnfiefish.com string=3b
参考:
LInux shell之(for in 用法总结)_wzj_110的博客-CSDN博客
https://www.jb51.net/article/100490.htm
linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 ) - gaomatlab - 博客园
Linux--shell脚本之正则表达式 - Sophie_h - 博客园
shell中的$IFS变量和$*_小龙在线-CSDN博客
shell 将字符串分割成数组 - cgj - 博客园
https://www.cnblogs.com/huangqihui/p/10675455.html
|