在bash脚本时性能enhancment [英] time performance enhancment in bash script

查看:165
本文介绍了在bash脚本时性能enhancment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同的文本文件和从不同的来源不同的输出。我需要有一个文本文档文件不同线路的输出。在code是如下:

I have different text files and different outputs from different sources. I need to have the output on different lines on a text document file. The code is as follows

for (( x = 1 ; x < 1000 ; x++ )) do

difference=$((file1 - file2))
echo $(tshark -r 1.pcap -c 1 -t ad | \
        awk -F" " '{print $2,$3}')  $difference \
        $(awk 'FNR == "'$z'" {print}' 1.txt) >> ~/Desktop/information.txt
done

它工作正常,但需要很长的时间。我beleive这是因为脚本访问文本文件多次在一个循环。任何想法如何使用其他方法来提高速度性能?

It works fine, but it takes a long time. I beleive it is because the script is accessing the text document many times in a loop. Any idea how to use other approaches to enhance the speed performance?

感谢

推荐答案

您可以采取重定向圈外的启动:

You can start with taking the redirection out of the loop:

for (( x = 1 ; x < 1000 ; x++ )) do
  difference=$((file1 - file2))
  echo $(tshark -r 1.pcap -c 1 -t ad | \
        awk -F" " '{print $2,$3}')  $difference \
        $(awk 'FNR == "'$z'" {print}' 1.txt)
done >> ~/Desktop/information.txt

这篇关于在bash脚本时性能enhancment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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