当前位置:首页 > 操作系统 > Linux

linux 手工打造脚本(帮同事处理EXCEL报表问题)优化版

     昨天帮同事写的脚本,由于只实现了基础功能没考虑过多其它,同事反馈运行很慢,由于时间原因当时没考虑处理大数据的情况,结果没有通过大数据的考验,程序运行了72分钟才出结果技术分享650) this.width=650;" src="/upload/getfiles/default/2022/11/7/20221107040509688.jpg" />


技术分享650) this.width=650;" src="/upload/getfiles/default/2022/11/7/20221107040509789.jpg" title="111.png" />

于是今天将代码做了一些优化和调整:


#!/bin/bash
#  Design By Jerry_江 (copyright (c)2011-2019)  
rm baogao2.txt baogao.txt baobiao.txt c.txt jxip.txt tmp.ym 1&>/dev/null
for i in `cat -A a.txt`
  do
  la=`echo $i |cut -d"^" -f1`
     lb=`grep $la b.txt|cat -A |cut -d"^" -f1`
     if [ "$la" == "$lb" ]
     then
     continue
     else
     echo $la  >>c.txt
     continue
     fi
done
for line in `cat -A c.txt`
 do
 ym=`echo $line |cut -d"$" -f1`
 ip=`nslookup $ym -timeout=0.01 |grep "Address: "|head -n 1|awk ‘{print $2}‘`
 echo "$ym" "$ip" >>jxip.txt
done
for line in `cat -A ip.txt`
 do
  ip=`echo $line |cut -d"^" -f1`
  grep  $ip  jxip.txt >>baobiao.txt
done
cat baobiao.txt |sort|uniq >baobiao2.txt
awk ‘BEGIN{print "域名   IP地址"} {print$1 "   " $2}‘ baobiao2.txt >baogao.txt

脚本最终输出数据为baogao.txt文件,其它为文件为程序临时生成文件,保留是了排错,听同事说有特殊情况,因此保留数据做备。

       听同事说他每天要花一个小时重复此项工作,因此写了此脚本,脚本基本实现了其需求,脚本中还有许多改进和优化的地方,多指教。

优化后大数据测试效果:技术分享650) this.width=650;" src="/upload/getfiles/default/2022/11/7/20221107040509987.jpg" />

技术分享650) this.width=650;" src="/upload/getfiles/default/2022/11/7/20221107040510039.jpg" title="3333.JPG" />


本文出自 “在路上……找回丢失的记忆” 博客,谢绝转载!

原文:http://jdonghong.blog.51cto.com/3473478/1958302


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐