首页 > 解决方案 > Take information from a file with grep

问题描述

I need to edit a huge file and only need to keep with the lines that start with [INFO].

I already tried

grep "'[^INFO]*'"

and

grep-i '\[^INFO]*'

among other and none of them worked.

Could you help me with this?

标签: linuxgrep

解决方案


正则表达式"'[^INFO]*'"匹配所有带有单引号且没有I, N,FO字符的行,请参见https://regex101.com/r/dDX5PQ/1。情况就是这样,因为[]是特殊字符,表示一系列字符。以^它开头时,表示不匹配的字符范围。

您想要的正则表达式是grep "^\[INFO\].*",它将匹配以[INFO]参见https://regex101.com/r/bIEoBx/2开头的所有行。


推荐阅读