Command line 匹配“的转义序列”;黑体字;在控制台中使用grep输出

Command line 匹配“的转义序列”;黑体字;在控制台中使用grep输出,command-line,grep,bold,Command Line,Grep,Bold,嗨,我有很多日志文件,里面有^[[1m(如vim所示)。我想通过 tail -n 1000 -f logfile.log | grep <expression-for-escape-sequence> 但是它不起作用……是的,在logfile.log的最后1000行中有粗体的行,使用 echo -e "\033\01331mTest\033\01330m" | grep ... 同样的结果…;) 感谢您的帮助!使用前面带有美元符号的单引号,如$“…”-让shell将\033转义序

嗨,我有很多日志文件,里面有^[[1m(如vim所示)。我想通过

tail -n 1000 -f logfile.log | grep <expression-for-escape-sequence>
但是它不起作用……是的,在logfile.log的最后1000行中有粗体的行,使用

echo -e "\033\01331mTest\033\01330m" | grep ...
同样的结果…;)


感谢您的帮助!

使用前面带有美元符号的单引号,如
$“…”
-让shell将
\033
转义序列转换为ESC字符:

tail -n 1000 -f logfile.log | grep $'\033\[1m'
人击

特殊处理
$'string'
形式的单词。该单词扩展为
字符串
,并按照ANSI C标准的规定替换反斜杠转义字符

这是可行的(在POSIX shell中,不一定是bash):


谢谢!这正是我要找的!搜索谷歌的解决方案真是一场噩梦,因为所有的特殊字符;)!
tail -n 1000 -f logfile.log | grep $'\033\[1m'
echo -e "\033\01331mTest\033\01330m" | grep "$(printf "\x1b\\[1m")"