使用grep查找包含一个字符串但不以另一个字符串开头的行 [英] Use grep to find lines containing a string, but not starting with another string

查看:81
本文介绍了使用grep查找包含一个字符串但不以另一个字符串开头的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的PHP .ini设置文件中查找会话配置标志.

I am looking up my session config flags in my PHP .ini settings file.

我使用此命令找到它们:

I use this command to find them:

 grep -i "session" php.ini

但是它返回以分号;"开头的注释和注释掉的参数.

But it returns comments and commented out parameters which start with semicolon ";".

如何更改命令,这样我仍然可以看到带有"session"的行,而不能以分号开头的行?

How can I change my command so I still get the lines with "session" in but not the ones that start with a semicolon?

推荐答案

grep -i "session" php.ini | grep -vx ';.*'

应该工作

-v是'invert match',因此仅显示不匹配的行

-v is 'invert match', so only lines that don't match are displayed

-x是整行匹配

这篇关于使用grep查找包含一个字符串但不以另一个字符串开头的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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