在Unix中用于特殊字符的grep [英] grep for special characters in Unix
本文介绍了在Unix中用于特殊字符的grep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个日志文件(application.log),它可能包含以下正常&多行特殊字符:
* ^%Q& $ *& ^ @ $& *!^ @ $ * &安培; ^&安培; ^ *&放大器; ^&安培;
我想搜索包含此特殊字符串的行号。
grep'* ^%Q& $ *& ^ @ $& *!^ @ $ * & ^& ^ *& ^&'application.log
上面的命令doesn'返回任何结果。
得到行数的正确语法是什么?
解决方案
通过使用 -F
选项,告诉 grep
将输入视为固定字符串。
grep -F'* ^%Q& $ *& ^ @ $& *!^ @ $ *& ^& ^ *& ^&'application.log
期权<$需要c $ c> -n 才能获得行号,
grep -Fn'* ^%Q& $ *& ^ @ $& *!^ @ $ *& ^& ^ *& ^&'application.log
I have a log file (application.log) which might contain the following string of normal & special characters on multiple lines:
*^%Q&$*&^@$&*!^@$*&^&^*&^&
I want to search for the line number(s) which contains this special character string.
grep '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log
The above command doesn't return any results.
What would be the correct syntax to get the line numbers?
解决方案
Tell grep
to treat your input as fixed string using -F
option.
grep -F '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log
Option -n
is required to get the line number,
grep -Fn '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log
这篇关于在Unix中用于特殊字符的grep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文