首页 > 系统服务 > 详细

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

时间:2017-08-22 15:44:57      阅读:379      评论:0      收藏:0      [点我收藏+]

     昨天帮同事写的脚本,由于只实现了基础功能没考虑过多其它,同事反馈运行很慢,由于时间原因当时没考虑处理大数据的情况,结果没有通过大数据的考验,程序运行了72分钟才出结果技术分享


技术分享

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


#!/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文件,其它为文件为程序临时生成文件,保留是了排错,听同事说有特殊情况,因此保留数据做备。

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

优化后大数据测试效果:技术分享

技术分享


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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!