我很好奇在以下情况下哪个更快。我有大约 2MB 的输出文件和数千行(我们会说在 15k - 50k 之间的任何地方)。
我正在文件末尾(最后 10 行)左右寻找一个字符串。我多次这样做,有时使用相同的文件的最后 10 行,并且用于多个文件。
我很好奇以下哪个是最快和最有效的:
tail最后 10 行,将它们保存为变量。当我需要grep或检查字符串时,echo该变量和grep输出- 每次我需要
grep一些东西时,首先tail是输出文件,然后pipe是grep输出 - 放弃上述任何一项,
grep每次只放弃整个文件。
选项1)
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