linux - 如何使用 linux shell 脚本删除 ^[ 和文件中的所有转义序列

我们要删除 ^[ 和所有转义序列。

sed 不工作,给我们这个错误:

$ 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 中:)

使用键盘输入:

sed 's/<kbd>Ctrl-v</kbd><kbd>Esc</kbd>//g'

或者

sed 's/<kbd>Ctrl-v</kbd><kbd>Ctrl-[</kbd>//g'

或者你可以使用字符转义:

sed 's/\x1b//g'

或全部control characters :

sed 's/[\x01-\x1F\x7F]//g' # NOTE: zaps TAB character too!

https://stackoverflow.com/questions/6534556/

相关文章:

linux - 区分 Windows 和类 Unix 系统的 Makefile

linux - 使用 find 列出所有图形图像文件?

javascript - 如何在没有 IDE 的情况下构建和部署三星 SmartTV 应用程序(例如

linux - Monit 守护程序 - 连接到 monit 守护程序时出错

linux - 更改/etc/profile 后,我需要做什么来重置我的 shell?

linux - 如何在/etc/fstab 中指定带有空格的标签/路径?

php - 如何通过 ssh 检查 ubuntu 服务器上是否存在 php 和 apache

linux - 基于shell中正则表达式的颜色突出显示输出

ssh - 从 PPK 文件创建 PEM

linux - 什么是适用于 Linux 的好的 Prolog IDE?