如何使用 linux shell 脚本删除 ^[ 以及文件中的所有转义序列 [英] How to remove ^[, and all of the escape sequences in a file using linux shell scripting
本文介绍了如何使用 linux shell 脚本删除 ^[ 以及文件中的所有转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们要删除 ^[
和所有转义序列.
We want to remove ^[
, and all of the escape sequences.
sed 不工作并给我们这个错误:
sed is not working and is giving us this error:
$ sed 's/^[//g' oldfile > newfile; mv newfile oldfile;
sed: -e expression #1, char 7: unterminated `s' command
$ sed -i '' -e 's/^[//g' somefile
sed: -e expression #1, char 7: unterminated `s' command
推荐答案
您在寻找 ansifilter?
您可以做两件事:输入字面转义(在 bash 中:)
Two things you can do: enter the literal escape (in bash:)
使用键盘输入:
sed 's/Ctrl-vEsc//g'
或者
sed 's/Ctrl-vCtrl-[//g'
或者你可以使用字符转义:
Or you can use character escapes:
sed 's/x1b//g'
或所有控制字符:
sed 's/[x01-x1Fx7F]//g' # NOTE: zaps TAB character too!
这篇关于如何使用 linux shell 脚本删除 ^[ 以及文件中的所有转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文