Linux
列印到文件沒有清晰的字元
我想將 docker stats 的輸出列印到文件中。
例如,我正在執行:
docker stats --format "{{ .Name }},{{ .MemUsage }},{{ .MemPerc }},{{ .CPUPerc }}" > /home/test.txt
但是,由於 docker stats 的正常輸出在更新的一行上,因此在文件中我列印出清晰的字元 (^[[3J^[[H^[[2J)]。
如何在沒有該字元的情況下列印輸出?
我還附上了一張圖片,以明確我在輸出中的內容。
您可以通過ansifilter管道它:
docker stats --format "{{ .Name }},{{ .MemUsage }},{{ .MemPerc }},{{ .CPUPerc }}" | ansifilter > /home/test.txt
請注意,
/home/test.txt
它將包含多行。它看起來像這樣:alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,656KiB / 7.476GiB,0.01%,0.00% alpine,528KiB / 7.476GiB,0.01%,0.00% alpine,528KiB / 7.476GiB,0.01%,0.00% alpine,528KiB / 7.476GiB,0.01%,0.03% alpine,528KiB / 7.476GiB,0.01%,0.03% alpine,528KiB / 7.476GiB,0.01%,0.02%