linux - 将顶部输出重定向到文件时可以看到特殊字符
问题描述
我正在尝试重定向 top 命令的输出,但我可以在文件中看到额外的特殊字符。
top -n 10 | grep --color=auto -i influx >> perf.txt
在文件中
(B[m21942 root 20 0 832268 286408 38792 S 5.9 0.9 478:07.97 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 8.3 0.9 478:08.22 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 0.7 0.9 478:08.25 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 3.0 0.9 478:08.34 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 0.3 0.9 478:08.35 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 0.3 0.9 478:08.36 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 3.3 0.9 478:08.46 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 0.3 0.9 478:08.47 influxd (B[m[39;49m[K
(B[m21942 root 20 0 832268 286408 38792 S 0.3 0.9 478:08.48 influxd (B[m[39;49m[K
我们如何避免上述特殊字符?
解决方案
该top
命令具有批处理模式 (-b),它将从输出中消除光标控制序列。根据手册页,它可以更容易地解析其他程序的输出。
此外,考虑从 grep 中删除--color
,这将引入控制序列以突出显示匹配项
top -b -n10 | grep influx >> perf.txt
推荐阅读
- javascript - windows.onunload 在 Chrome 上不起作用
- .net - 如何使用 SDK 创建用于创建 Azure Bot 服务的 MSA Id 和密码
- mysql - 没有子查询的mysql/postgres窗口函数限制结果
- swift - 如何在 UITableVIew 的不同单元格中使用 UITextView 获取用户输入
- jquery - 如何更改特定的菜单项文本颜色?背景改变但文字颜色没有改变?
- r - 单击传单标记并获取信息
- java - 从 Java 中的路径字符串生成嵌套映射
- mysql - Sequelize 得到没有对象的纯数组
- sql - 使用 Postgres 进行预测
- java - 使用 javafx 从 mysql 数据库中获取图像