gpt4 book ai didi

linux - 寻找类似 "tee"但每次写入都会打开/关闭目标文件的内容?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:21 25 4
gpt4 key购买 nike

我有类似mycommand | tee -a mylogfile.log 但是因为日志文件驻留在磁盘上,可能会一遍又一遍地重新安装,所以我想让 tee 在每次写入时打开/关闭文件(比如,例如每一行)。有没有办法完成这样的事情?

最佳答案

这将打开和关闭 mylogfile.log 每行:

mycommand | while IFS= read -r line; do printf "%s\n" "$line" | tee -a mylogfile.log; done

使用 bash,这可以稍微简化:

mycommand | while IFS= read -r line; do tee -a mylogfile.log <<<"$line"; done

关于linux - 寻找类似 "tee"但每次写入都会打开/关闭目标文件的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32162482/

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