Bash 将curl progress输出的最后一行提取到变量中

Bash 将curl progress输出的最后一行提取到变量中,bash,curl,Bash,Curl,我有一个文件output.txt,其中包含一个cURL progress输出,如 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:

我有一个文件
output.txt
,其中包含一个cURL progress输出,如

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0  490M    0     0    0  208k      0   248k  0:33:43 --:--:--  0:33:43  248k
  0  490M    0     0    0  256k      0   157k  0:53:11  0:00:01  0:53:10  157k
  0  490M    0     0    0  368k      0   140k  0:59:49  0:00:02  0:59:47  140k
  3  490M    0     0    3 19.5M      0   155k  0:53:50  0:02:08  0:51:42  153k
  3  490M    0     0    3 19.6M      0   154k  0:54:05  0:02:09  0:51:56  141k
  4  490M    0     0    4 19.7M      0   154k  0:54:06  0:02:10  0:51:56  120k
我只想提取最后一行。当我这样做时:

LASTLINE=$(tail -n1 output.txt)
很明显,即使是

echo $LASTLINE
显示最后一行,它包含所有内容作为证据:

echo "${#LASTLINE}"

其中显示了
709
,字符数的计数,但最后一行应该只有79个字符。我知道这是关于缓冲区的。发生了什么事?

该文件中有回车符。使用sed清除前面的所有内容,包括最后一个:

LASTLINE=$(sed '$!d;s/.*\r//' output.txt)

什么是
${#LASTLINE}
以及您希望它是什么?(另外,不要对您自己的变量使用所有的大写字母。有关详细信息,请参阅)它应该是
449M 0 0 4 19.7M 0 154k 0:54:06 0:02:10 0:51:56 120k
{code>${LASTLINE}应该只是一个数字。无法复制,顺便说一句。
foo=$(tail-n1 output.txt)&&echo“${#foo}”
给我78。