匹配“粗体”的转义序列在控制台输出中使用 grep
你好,我有很多日志文件,其中包含 ^[[1m (如 vim 显示的那样)。我想通过观看日志文件的生活
tail -n 1000 -f logfile.log | grep <expression-for-escape-sequence>
,并且只获取其中包含粗体的行。 我不确定应该使用哪些 grep 选项,并且已经尝试过以下操作:
tail -n 1000 -f logfile.log | grep "\033\0133\061\0155"
tail -n 1000 -f logfile.log | grep "\033\01331m"
tail -n 1000 -f logfile.log | grep "\033\[1m"
但它不起作用...是的,logfile.log 的最后 1000 行中有粗体行,测试
echo -e "\033\01331mTest\033\01330m" | grep ...
结果相同...;)
感谢任何帮助!
Hi I have lots of logfiles with ^[[1m (as vim displays it) in them. I want to watch a logfile life via
tail -n 1000 -f logfile.log | grep <expression-for-escape-sequence>
and only get lines that have bold in them.
I am not sure which grep options I should use and have tried the following already:
tail -n 1000 -f logfile.log | grep "\033\0133\061\0155"
tail -n 1000 -f logfile.log | grep "\033\01331m"
tail -n 1000 -f logfile.log | grep "\033\[1m"
It does not work though... And yes there are bold lines in the last 1000 lines of logfile.log, testing with
echo -e "\033\01331mTest\033\01330m" | grep ...
same results... ;)
Appreciate any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用前面带有美元符号的单引号(如
$'...'
所示),让 shell 将\033
转义序列转换为 ESC 字符:强>男人重击:
Use single quotes with a dollar sign in front—as in
$'...'
—to have the shell convert the\033
escape sequence into an ESC character:From man bash:
这是可行的(在 POSIX shell 中,不一定是 bash):
This works (in a POSIX shell, not necessarily bash):