栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

shell 之grep,awk,for in

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

shell 之grep,awk,for in

 删除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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/333756.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号