0

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?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Matias
  • 13
  • 3
  • 1
    Possible duplicate of [How do I grep for strings with special characters like \[\]?](https://stackoverflow.com/q/18227567/608639), [grep for special characters in Unix](https://stackoverflow.com/q/12387685/608639), [Escape characters in grep](https://stackoverflow.com/q/42822174/608639), [In a regular expression, which characters need escaping?](https://unix.stackexchange.com/q/20804/56041), [escape character used in grep](https://askubuntu.com/q/851848), etc – jww Sep 11 '18 at 15:19

1 Answers1

1

The regex "'[^INFO]*'" matches all lines with single quotes and no I, N, F or O characters see https://regex101.com/r/dDX5PQ/1 . This is the case, because [ and ] are special characters and denote a rango of characters. When started with ^ it denotes a range of characters not to match.

The regex you want is grep "^\[INFO\].*", which will match on all lines that start with [INFO] see https://regex101.com/r/bIEoBx/2 .

FlyingFoX
  • 3,379
  • 3
  • 32
  • 49