Unix 中特殊字符的 grep [英] grep for special characters in Unix

查看:32
本文介绍了Unix 中特殊字符的 grep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日志文件 (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?

推荐答案

使用 -F 选项告诉 grep 将您的输入视为固定字符串.

Tell grep to treat your input as fixed string using -F option.

grep -F '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log

Option -n 需要获取行号,

Option -n is required to get the line number,

grep -Fn '*^%Q&$*&^@$&*!^@$*&^&^*&^&' application.log

这篇关于Unix 中特殊字符的 grep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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