哪个更快?回声variables,或尾巴长的输出文件,或者也许`grep`整个事情

哪个更快?回声variables,或尾巴长的输出文件,或者也许`grep`整个事情,第1张

概述哪个更快? 回声variables,或尾巴长的输出文件,或者也许`grep`整个事情

我很好奇,在以下情况下更快。 我有大约2MB的输出文件和数千行(在15k – 50k之间的任何地方)。

我正在寻找一个string在文件的末尾(最后10行)左右。 我多次执行此 *** 作,有时使用相同的最后10行文件,以及多个文件。

我很好奇以下哪个是最快最有效的:

tail最后10行,保存为一个variables。 当我需要grep或检查一个string时,在输出中echo该variables和grep

每次我需要grep东西,首先tail输出文件,然后pipe和grep的输出

放弃上面的任何一个,每次grep整个文件。

选项1)

如何连续显示其最后几行内容的文件

获取windows中一个巨大文件的最后n行或者字节(比如Unix的尾部)。 避免耗时的select

自停尾部 *** 作

C基本的头部命令

尾巴只有一行的前几个字符

if [ -f "$jobfile".out ]; then { output=$(tail -n 10 "$jobfile".out) !((echo "$output" | grep -q "Command exited with non-zero status" ) || (echo "$output" | grep -q "Error termination via Lnk1e")) && continue { output "$(grep $jobID $curJobsfile)" sed -i "/$jobID/d" "$jobIDsWithServer" } fi

选项2)

if [ -f "$jobfile".out ]; then { !((tail -n 10 "$jobfile".out | grep -q "Command exited with non-zero status" ) || (tail -n 10 "$jobfile".out | grep -q "Error termination via Lnk1e")) && continue { output "$(grep $jobID $curJobsfile)" sed -i "/$jobID/d" "$jobIDsWithServer" } fi

选项3)

if [ -f "$jobfile".out ]; then { !((grep -q "Command exited with non-zero status" "$jobfile".out) || (grep -q "Error termination via Lnk1e" "$jobfile".out)) && continue { output "$(grep $jobID $curJobsfile)" sed -i "/$jobID/d" "$jobIDsWithServer" } fi

在bash脚本中运行tail -f特定的时间

尾文件 – 统计给定模式的行数

如何cygwin尾巴在c:/ wamp / logs /文件在windows?

grep文本与通配符inbetween

尾巴-f总是使用inotify?

选项2使用尾巴两次,所以可能会比1稍慢。两者比选项3要快得多。

你可以做的另一件事是:

if [ -f "$jobfile".out ]; then { !(tac "$jobfile".out | grep -E -m1 -q "(Command exited with non-zero status|Error termination via Lnk1e)") && continue { output "$(grep $jobID $curJobsfile)" sed -i "/$jobID/d" "$jobIDsWithserver" } fi

这将以相反的顺序输出文件,grep将在第一次匹配后停止。 此外,它将同时搜索两个搜索条件,如果与第一项不匹配,则不必再次grep两次。

为什么不是这样的:

if tail -f "$jobfile.out" | grep -F -e "Command exited with non-zero status" -e "Error termination via Lnk1e" then output "$(grep $jobID $curJobsfile)" sed -i "/$jobID/d" "$jobIDsWithserver" fi

这样,您就可以实时查看尾部的输出,直到找到所需的内容。

在不使用正则表达式的情况下,在grep中使用-F标志会使速度更快。

总结

以上是内存溢出为你收集整理的哪个更快? 回声variables,或尾巴长的输出文件,或者也许`grep`整个事情全部内容,希望文章能够帮你解决哪个更快? 回声variables,或尾巴长的输出文件,或者也许`grep`整个事情所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1275092.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存