linux - 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?
解决方案
正则表达式"'[^INFO]*'"
匹配所有带有单引号且没有I
, N
,F
或O
字符的行,请参见https://regex101.com/r/dDX5PQ/1。情况就是这样,因为[
和]
是特殊字符,表示一系列字符。以^
它开头时,表示不匹配的字符范围。
您想要的正则表达式是grep "^\[INFO\].*"
,它将匹配以[INFO]
参见https://regex101.com/r/bIEoBx/2开头的所有行。
推荐阅读
- javascript - 具有动态宽度的裁剪 div 的 clientWidth 值不正确(使用 useLayoutEffect 和 SSR)
- ag-grid - 如何在 AG-grid 中创建具有相同名称的不同员工的不同行组?
- laravel - 如何解决 ErrorException:找不到必需的 @OA\PathItem()
- c++ - VkSurfaceKHR 指针的值在没有任何显式赋值的函数调用后发生变化
- haskell - Applying an existentially typed function to a sufficiently polymorphic argument
- user-interface - 等待 Navigator.pop() 完成工作
- c++ - Sublime-text3 将 } 高亮显示为非法字符
- java - 验证字符串列表的最简单方法是仅在 java 中的字母数字
- reverse-proxy - Azure 服务结构概念
- google-cloud-platform - GCP 日志记录 - 不导出到任何接收器的只读日志