使用sed删除颜色代码(特殊字符)

这个命令建立在这里发布的一些原始命令上。增加控制顺序\ x1b(B选择缺省字符集ASCII.- \ x1B样式转义序列或\ 033.-使用'I'不区分大小写'在后半部分包含\ x1b,\ x1B转义和a-zA-Z在makefile无缓冲的输出上进行广泛测试,其中上述添加被证明是必要的
.

0

linux命令:sed -r "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig" "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig" -r sed sed -r "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig"rootopen.com
linux命令:sed -r "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig" "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig" -r sed sed -r "s/(\x1B|\033)(\(B|\[([0-9]{1,2}(;[0-9]{1,2})?)?[A-Z])//Ig"rootopen.com
zxiq 2018-01-01 14:40:48
输出
linux命令:sed 详解
替代方案1 使用sed删除颜色代码(特殊字符)

使用sed删除颜色代码(特殊字符).

linux命令:<ctrl+a> <ctrl+a> <ctrl+a>rootopen.com
linux命令:<ctrl+a> <ctrl+a> <ctrl+a>rootopen.com
.
输出
替代方案2 使用sed删除颜色代码(特殊字符)

.

linux命令:sed -r "s@\^\[{1,2}([0-9]{1,2}(;[0-9]{1,2})?(;[0-9])?(m|K){1,2})?@@g" "s@\^\[{1,2}([0-9]{1,2}(;[0-9]{1,2})?(;[0-9])?(m|K){1,2})?@@g" -r sed sed -r "s@\^\[{1,2}([0-9]{1,2}(;[0-9]{1,2})?(;[0-9])?(m|K){1,2})?@@g"rootopen.com
linux命令:sed -r "s@\^\[{1,2}([0-9]{1,2}(;[0-9]{1,2})?(;[0-9])?(m|K){1,2})?@@g" "s@\^\[{1,2}([0-9]{1,2}(;[0-9]{1,2})?(;[0-9])?(m|K){1,2})?@@g" -r sed sed -r "s@\^\[{1,2}([0-9]{1,2}(;[0-9]{1,2})?(;[0-9])?(m|K){1,2})?@@g"rootopen.com
.
输出
替代方案3 使用sed删除颜色代码(特殊字符)

除了标准的16色ANSI表单外,还处理用于256色终端的颜色代码(如xterm-(256)color和urxvt-unicode-256color)。 要获得严格的ANSI输出,请参阅其他更简单的选项。.

linux命令:sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" -r sed sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"rootopen.com
linux命令:sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" -r sed sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"rootopen.com
.
输出
替代方案4 使用sed删除颜色代码(特殊字符)

从流或文件中移除ANSI颜色.

linux命令:sed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g' "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g' -e 's/'$(echo -r sed sed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g'rootopen.com
linux命令:sed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g' "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g' -e 's/'$(echo -r sed sed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g'rootopen.com
.
输出
替代方案5 使用sed删除颜色代码(特殊字符)

.

linux命令:cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g' 's/\\\033[^a-zA-Z]*.//g' sed | input.txt cat cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g'rootopen.com
linux命令:cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g' 's/\\\033[^a-zA-Z]*.//g' sed | input.txt cat cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g'rootopen.com
.
输出
替代方案6 使用sed删除颜色代码(特殊字符)

.

linux命令:sed -r "s:\x1B\[[0-9;]*[mK]::g"' "s:\x1B\[[0-9;]*[mK]::g"' -r sed sed -r "s:\x1B\[[0-9;]*[mK]::g"'rootopen.com
linux命令:sed -r "s:\x1B\[[0-9;]*[mK]::g"' "s:\x1B\[[0-9;]*[mK]::g"' -r sed sed -r "s:\x1B\[[0-9;]*[mK]::g"'rootopen.com
.
输出
替代方案7 使用sed删除颜色代码(特殊字符)

将ANSI颜色和行尾代码移除为[{attr1}; ...; {attrn} m格式。.

linux命令:sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g -r sed sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//grootopen.com
linux命令:sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g -r sed sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//grootopen.com
.
输出
替代方案8 使用sed删除颜色代码(特殊字符)

.

linux命令:sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" -r sed sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"rootopen.com
linux命令:sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" -r sed sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"rootopen.com
.
输出

评论

相关推荐

命令将打印指定文件的第101行和第106行。 -n默认情况下,将使sed不打印所有行。 该-e是指定一个sed命令,你可以一次多次使用它。

linux命令:sed -ne '101 p' -e '106 p' /path/to/the/file /path/to/the/file p' '106 -e p' '101 -ne sed sed -ne '101 p' -e '106 p' /path/to/the/filerootopen.com
linux命令:sed -ne '101 p' -e '106 p' /path/to/the/file /path/to/the/file p' '106 -e p' '101 -ne sed sed -ne '101 p' -e '106 p' /path/to/the/filerootopen.com
.

删除文件中的\ r \ n(回车)

linux命令:sed -i 's/\r//g somefile.txt somefile.txt 's/\r//g -i sed sed -i 's/\r//g somefile.txtrootopen.com
linux命令:sed -i 's/\r//g somefile.txt somefile.txt 's/\r//g -i sed sed -i 's/\r//g somefile.txtrootopen.com
.

转义引号,从JSON中删除换行符,制表符和空格

linux命令:sed 's / \“/ \\\”/ g'json_file | tr -d '\ n' | tr -d '[[:blank:]]' '[[:blank:]]' -d tr | n' '\ -d tr | g'json_file \\\”/ \“/ / 's sed sed 's / \“/ \\\”/ g'json_file | tr -d '\ n' | tr -d '[[:blank:]]'rootopen.com
linux命令:sed 's / \“/ \\\”/ g'json_file | tr -d '\ n' | tr -d '[[:blank:]]' '[[:blank:]]' -d tr | n' '\ -d tr | g'json_file \\\”/ \“/ / 's sed sed 's / \“/ \\\”/ g'json_file | tr -d '\ n' | tr -d '[[:blank:]]'rootopen.com
.

linux命令:sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | head head | -nr sort | -cd uniq | sort | ~/.bash_history *$//' 's/ -e sed sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | headrootopen.com
linux命令:sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | head head | -nr sort | -cd uniq | sort | ~/.bash_history *$//' 's/ -e sed sed -e 's/ *$//' ~/.bash_history | sort | uniq -cd | sort -nr | headrootopen.com
.

Sed在比赛中停止解析,因此比管道尾部或类似物更有效。使用'999995,1000005!d'<my_massive_file获取一行范围

linux命令:sed '1000000!d;q' < massive-log-file.log massive-log-file.log < '1000000!d;q' sed sed '1000000!d;q' < massive-log-file.logrootopen.com
linux命令:sed '1000000!d;q' < massive-log-file.log massive-log-file.log < '1000000!d;q' sed sed '1000000!d;q' < massive-log-file.logrootopen.com
.

linux命令:sed -e '/^[<space><tab>]*$/d' somefile somefile '/^[<space><tab>]*$/d' -e sed sed -e '/^[<space><tab>]*$/d' somefilerootopen.com
linux命令:sed -e '/^[<space><tab>]*$/d' somefile somefile '/^[<space><tab>]*$/d' -e sed sed -e '/^[<space><tab>]*$/d' somefilerootopen.com
.

从Cisco配置中为John the Ripper设置密码文件(级别5)从http://www.openwall.com/lists/john-users/2006/05/14/8

linux命令:sed -n 's/[ :]/_/g; s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' < cisco-device-config > passwd passwd > cisco-device-config < s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' :]/_/g; 's/[ -n sed sed -n 's/[ :]/_/g; s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' < cisco-device-config > passwdrootopen.com
linux命令:sed -n 's/[ :]/_/g; s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' < cisco-device-config > passwd passwd > cisco-device-config < s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' :]/_/g; 's/[ -n sed sed -n 's/[ :]/_/g; s/^\(.\{1,\}\)_5_\($1$[$./0-9A-Za-z]\{27,31\}\)_*$/\1:\2/p' < cisco-device-config > passwdrootopen.com
.

非常快速地更改文件中的单词。我一直用它来改变PHP脚本中的变量名(sed -i's / $ oldvar / $ newvar / g'index.php)

linux命令:sed -i 's/OLD/NEW/g' FILE FILE 's/OLD/NEW/g' -i sed sed -i 's/OLD/NEW/g' FILErootopen.com
linux命令:sed -i 's/OLD/NEW/g' FILE FILE 's/OLD/NEW/g' -i sed sed -i 's/OLD/NEW/g' FILErootopen.com
.

原位搜索替换,但留下了有日期戳的备份。更精确的变体:sed -i.`date +%Y%m%d%H%M%S'/ pattern / replace'[文件名]

linux命令:sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename] [filename] 's/pattern/replace' -e +%Y%m%d` -i.`date sed sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename]rootopen.com
linux命令:sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename] [filename] 's/pattern/replace' -e +%Y%m%d` -i.`date sed sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename]rootopen.com
.

如果文件内容是:-blah blah blahABChello等等等等等等等等等,你会得到:-ABChello等等等等等等等等等blohDEF

linux命令:sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n" "\n" "~" tr | "^ABC" grep | "\n" "+" tr | "~" "\n" tr | "s/DEF$/DEF+/" sed | <file "s/^ABC/+ABC/" sed sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n"rootopen.com
linux命令:sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n" "\n" "~" tr | "^ABC" grep | "\n" "+" tr | "~" "\n" tr | "s/DEF$/DEF+/" sed | <file "s/^ABC/+ABC/" sed sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n"rootopen.com
.

linux命令:sed -e :a -e '/$/N;s/\n/ /;ta' <filename> <filename> /;ta' '/$/N;s/\n/ -e :a -e sed sed -e :a -e '/$/N;s/\n/ /;ta' <filename>rootopen.com
linux命令:sed -e :a -e '/$/N;s/\n/ /;ta' <filename> <filename> /;ta' '/$/N;s/\n/ -e :a -e sed sed -e :a -e '/$/N;s/\n/ /;ta' <filename>rootopen.com
.

特别感谢XwZ :)

linux命令:sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta' /;ta' '/$/N;s/\n/ -e :a -e sed | /etc/group "/$USER/d;s/:.*//g" -e sed sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta'rootopen.com
linux命令:sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta' /;ta' '/$/N;s/\n/ -e :a -e sed | /etc/group "/$USER/d;s/:.*//g" -e sed sed -e "/$USER/d;s/:.*//g" /etc/group | sed -e :a -e '/$/N;s/\n/ /;ta'rootopen.com
.

当主机的ssh密钥发生变化并且ssh拒绝连接到机器时,它非常有用,同时给你在〜/ .ssh / known_hosts中更改的行号。

linux命令:sed -i '10d' <somefile> <somefile> '10d' -i sed sed -i '10d' <somefile>rootopen.com
linux命令:sed -i '10d' <somefile> <somefile> '10d' -i sed sed -i '10d' <somefile>rootopen.com
.

linux命令:sed 's/$'"/`echo \\\r`/" \\\r`/" 's/$'"/`echo sed sed 's/$'"/`echo \\\r`/"rootopen.com
linux命令:sed 's/$'"/`echo \\\r`/" \\\r`/" 's/$'"/`echo sed sed 's/$'"/`echo \\\r`/"rootopen.com
.

删除前55行;将55改为任意数字

linux命令:sed '1,55d' '1,55d' sed sed '1,55d'rootopen.com
linux命令:sed '1,55d' '1,55d' sed sed '1,55d'rootopen.com
.

linux命令:sed '/./,$!d' '/./,$!d' sed sed '/./,$!d'rootopen.com
linux命令:sed '/./,$!d' '/./,$!d' sed sed '/./,$!d'rootopen.com
.

ctrl + v,ctrl + m部分表示您应该执行的按键操作。如果你成功地做到了,你会看到一个^ M字符出现。

linux命令:sed 's/$/<ctrl+v><ctrl+m>/' 's/$/<ctrl+v><ctrl+m>/' sed sed 's/$/<ctrl+v><ctrl+m>/'rootopen.com
linux命令:sed 's/$/<ctrl+v><ctrl+m>/' 's/$/<ctrl+v><ctrl+m>/' sed sed 's/$/<ctrl+v><ctrl+m>/'rootopen.com
.

linux命令:sed 's/$//' 's/$//' sed sed 's/$//'rootopen.com
linux命令:sed 's/$//' 's/$//' sed sed 's/$//'rootopen.com
.

linux命令:sed '1!G;h;$!d' '1!G;h;$!d' sed sed '1!G;h;$!d'rootopen.com
linux命令:sed '1!G;h;$!d' '1!G;h;$!d' sed sed '1!G;h;$!d'rootopen.com
.

我有时会在文件中存储大量的MAC地址文件,有些数据库需要使用分号存储的信息(使设备更容易编程),而其他数据库则不需要。 awk'{for(i = 10; i> = 2; i- = 2)$ 0 = substr()我有一个条形码文本文件扫描器,通常屠杀MAC地址,所以这是修复> $ 0,1,i)“:”substr($ 0,i + 1); print}'mac_address_list

linux命令:sed 's/\(..\)/\1:/g;s/:$//' mac_address_list mac_address_list 's/\(..\)/\1:/g;s/:$//' sed sed 's/\(..\)/\1:/g;s/:$//' mac_address_listrootopen.com
linux命令:sed 's/\(..\)/\1:/g;s/:$//' mac_address_list mac_address_list 's/\(..\)/\1:/g;s/:$//' sed sed 's/\(..\)/\1:/g;s/:$//' mac_address_listrootopen.com
.
共收录0条命令行
这里是记录和分享命令行的地方, 所有命令行都可以进行评论、提交替代方案.

推荐
    热门命令