【发布时间】:2013-08-02 15:59:56
【问题描述】:
我有一些产生颜色输出的脚本,我需要删除 ANSI 代码。
#!/bin/bash
exec > >(tee log) # redirect the output to a file but keep it on stdout
exec 2>&1
./somescript
输出是(在日志文件中):
java (pid 12321) is running...@[60G[@[0;32m OK @[0;39m]
我不知道怎么把 ESC 字符放在这里,所以我把@ 放在它的位置。
我把脚本改成:
#!/bin/bash
exec > >(tee log) # redirect the output to a file but keep it on stdout
exec 2>&1
./somescript | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
但现在它给了我(在日志文件中):
java (pid 12321) is running...@[60G[ OK ]
我怎样才能删除这个'@[60G?
也许有一种方法可以完全禁用整个脚本的着色?
【问题讨论】:
-
对于node/npm,可以使用
strip-ansi:github.com/chalk/strip-ansi。
标签: bash unix colors console ansi-escape