for ((i=1; i<=$count; i++)); do timestamp=$(sed -n "${i}p" <<< "$timestamps") subject=$(sed -n "${i}p" <<< "$subjects") sender=$(sed -n "${i}p" <<< "$isenders") recipient=$(sed -n "${i}p" <<< "$recipients") if [[ "$timestamp" > "$time" && "$timestamp" < "$(date +"%Y-%m-%d %H:%M:%S")" ]]; then printf "%-10s %-60s %-30s %-30s\n" "$timestamp" "$subject" "$sender" "$recipient" >> "$result_file" 2>&1 | tee "$result_log" fi done
时间: 2023-08-05 12:10:53 浏览: 151
根据您提供的代码,您想使用循环逐行处理日志信息,并根据时间范围条件将结果输出到文件并同时显示在终端上。然而,您的代码中存在一个拼写错误,导致无法正确提取发件人字段。请使用以下修正后的代码:
```shell
for ((i=1; i<=$count; i++)); do
timestamp=$(sed -n "${i}p" <<< "$timestamps")
subject=$(sed -n "${i}p" <<< "$subjects")
sender=$(sed -n "${i}p" <<< "$senders")
recipient=$(sed -n "${i}p" <<< "$recipients")
if [[ "$timestamp" > "$time" && "$timestamp" < "$(date +"%Y-%m-%d %H:%M:%S")" ]]; then
printf "%-10s %-60s %-30s %-30s\n" "$timestamp" "$subject" "$sender" "$recipient"
printf "%-10s %-60s %-30s %-30s\n" "$timestamp" "$subject" "$sender" "$recipient" >> "$result_file" 2>&1 | tee -a "$result_log"
fi
done
```
在这个修正后的代码中,我将 `isenders` 修正为 `senders`,以正确提取发件人字段。另外,请注意在 `printf` 命令中使用 `-a` 选项来追加结果到文件 `$result_log` 中的修正。
请确保将 `$result_file` 和 `$result_log` 替换为实际的文件路径。如果还有其他问题,请随时告诉我。
阅读全文