gpt4 book ai didi

linux - 文件的最后一行被截断

转载 作者:太空宇宙 更新时间:2023-11-04 12:43:46 24 4
gpt4 key购买 nike

文件的最后一行被截断

这是我的代码:

#!/bin/bash
filetouse=$1
while read -r STUDENTID FIRST LAST C1 C2 C3
do
totalSum=$(expr $C1 + $C2 + $C3)
average=$(expr $totalSum / 3)
printf '%d [%d] %s, %s\n' "$average" "$STUDENTID" "$LAST" "$FIRST"
done < "$filetouse" | sort -k 3,3n -k 4,4n -k 2,2g

预期输出=

71 [299226663] Camp, Laney
80 [434401929] Camp, Skyler
81 [199144454] Camp, Tracey
93 [928441032] Forester, Chris
82 [928441032] Forester, Jess
92 [888111818] Forney, JC
82 [123456789] Johnson, Lee
99 [290010111] Lee, Terry
91 [999999999] Smith, Jaime

实际输出=

71 [299226663] Camp, Laney
80 [434401929] Camp, Skyler
81 [199144454] Camp, Tracey
82 [928441032] Forester, Jess
92 [888111818] Forney, JC
82 [123456789] Johnson, Lee
99 [290010111] Lee, Terry
91 [999999999] Smith, Jaime

我从代码中注意到

82 [928441032] Forester, Jess

不见了。它也恰好是文件的最后一行。但我不确定为什么最后一行被截断了。

我正在使用的文件 =测试.sh

123456789 Lee Johnson 72 85 90
999999999 Jaime Smith 90 92 91
888111818 JC Forney 100 81 97
290010111 Terry Lee 100 99 100
199144454 Tracey Camp 77 84 84
299226663 Laney Camp 70 74 71
434401929 Skyler Camp 78 81 82
928441032 Jess Forester 85 80 82
928441032 Chris Forester 97 94 89

最佳答案

我在没有修改的情况下运行了你的脚本,得到了这个:

#./script.sh input.txt 
71 [299226663] Camp, Laney
80 [434401929] Camp, Skyler
81 [199144454] Camp, Tracey
82 [123456789] Johnson, Lee
82 [928441032] Forester, Jess
91 [999999999] Smith, Jaime
92 [888111818] Forney, JC
93 [928441032] Forester, Chris
99 [290010111] Lee, Terry

它确实显示了带有 93 的那个。

关于linux - 文件的最后一行被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39404685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com