This question already has an answer here:
这个问题在这里已有答案:
- How to remove ^[, and all of the escape sequences in a file using linux shell scripting 8 answers
- 如何使用linux shell脚本8答案删除^ [,以及文件中的所有转义序列
I am trying to replace some sequence of character with a blank. But I am not able to replace it.
我试图用空白替换一些字符序列。但我无法取代它。
File name is Test:
文件名是Test:
id ^[[0mevent^[[0m ^[[0msuite^[[0m ^[[0mok^[[0m ^[[0mnok^[[0m ^[[0mskip^[[0m test up owner du duplex type stp inst_type prep created finished
I am trying to replace ^[[0m
with a blank character. To do so I am using the following command to achieve the aforementioned task.
我试图替换^ [[0m与空白字符。为此,我使用以下命令来完成上述任务。
sed 's/\^\[\[0m//g' Test
However, the above command is having not impact.
但是,上述命令没有影响。
The problem is due to coloured font.
问题是由于彩色字体。
Thanks!!
谢谢!!
2 个解决方案
#1
1
You are replacing it with z
just remove the z
also instead of 0 seems that you have typed big O
. Change it to 0
then it will work very well:
您正在用z替换它只是删除z而不是0似乎您已经键入了大O.将其更改为0然后它将工作得很好:
~$ echo "id ^[[0mevent^[[0m ^[[0msuite^[[0m"|sed 's/\^\[\[0m//g'
id event suite
#2
0
I have used the following command to replace the colored text:
我使用以下命令替换彩色文本:
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" abc
Source: http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
资料来源:http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
#1
1
You are replacing it with z
just remove the z
also instead of 0 seems that you have typed big O
. Change it to 0
then it will work very well:
您正在用z替换它只是删除z而不是0似乎您已经键入了大O.将其更改为0然后它将工作得很好:
~$ echo "id ^[[0mevent^[[0m ^[[0msuite^[[0m"|sed 's/\^\[\[0m//g'
id event suite
#2
0
I have used the following command to replace the colored text:
我使用以下命令替换彩色文本:
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" abc
Source: http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
资料来源:http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed