gpt4 book ai didi

bash - 如何正确实时输出bash到文本文件?

转载 作者:行者123 更新时间:2023-11-29 09:04:39 29 4
gpt4 key购买 nike

我想这样做并将其保存到一个文本文件中,比如 abc.txt。

top | grep "Cpu(s)"

我知道我可以在 bash 中做到这一点

top | stdbuf -o0 grep "Cpu(s)" > abc.txt

我的输出是正确的,但是当我在 gedit 中打开 txt 文件时,它看起来像这样:

Cpu(s): (B [m [39;49m (B [m  1.0% (B [m [39;49mus, (B [m [39;49m (B [m  0.3% (B [m [39;49msy, (B [m [39;49m (B [m  0.6% (B [m [39;49mni, (B [m [39;49m (B [m 97.9% (B [m [39;49mid, (B [m [39;49m (B [m  0.1% (B [m [39;49mwa, (B [m [39;49m (B [m  0.0% (B [m [39;49mhi, (B [m [39;49m (B [m  0.0% (B [m [39;49msi, (B [m [39;49m (B [m  0.0% (B [m [39;49mst (B [m [39;49m [K
Cpu(s): (B [m [39;49m (B [m 0.7% (B [m [39;49mus, (B [m [39;49m (B [m 1.0% (B [m [39;49msy, (B [m [39;49m (B [m 0.0% (B [m [39;49mni, (B [m [39;49m (B [m 98.3% (B [m [39;49mid, (B [m [39;49m (B [m 0.0% (B [m [39;49mwa, (B [m [39;49m (B [m 0.0% (B [m [39;49mhi, (B [m [39;49m (B [m 0.0% (B [m [39;49msi, (B [m [39;49m (B [m 0.0% (B [m [39;49mst (B [m [39;49m [K`

Instead of this:

​Cpu(s): 1.0%us, 0.3%sy, 0.6%ni, 97.9%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu(s): 0.7%us, 1.0%sy, 0.0%ni, 98.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st

最佳答案

使用top -b 删除所有特殊显示字符:

top -b | grep "Cpu(s)" > abc.txt

关于bash - 如何正确实时输出bash到文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23310544/

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