如何使用Linux Shell脚本删除^ [和文件中的所有转义序列 [英] How to remove ^[, and all of the escape sequences in a file using linux shell scripting

查看:131
本文介绍了如何使用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-\x1F\x7F]//g' # NOTE: zaps TAB character too!

这篇关于如何使用Linux Shell脚本删除^ [和文件中的所有转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆