加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – 检查一行是否以grep 的特定字符串开头

发布时间:2020-12-15 18:58:09 所属栏目:安全 来源:网络整理
导读:参见英文答案 Linux,Print all lines in a file,NOT starting with5个 我有一个文件app.log Oct 06 03:51:43 test testNov 06 15:04:53 text text text more text more textNov 06 15:06:43 text text textNov 06 15:07:33more text more textNov 06 15:14:2
参见英文答案 > Linux,Print all lines in a file,NOT starting with5个
我有一个文件app.log
Oct 06 03:51:43 test test
Nov 06 15:04:53 text text text 
more text more text
Nov 06 15:06:43 text text text
Nov 06 15:07:33
more text more text
Nov 06 15:14:23  test test
more text more text
some more text 
Nothing but text
some extra text
Nov 06 15:34:31 test test test

我如何使用11月06日开始的所有线路?

我努力了

grep -En "^[^Nov 06]" app.log

我无法获得其中有06的线条.

只需使用下面的grep命令,
grep -v '^Nov 06' file

来自grep –help,

-v,--invert-match        select non-matching lines

另一个通过正则表达式破解,

grep -P '^(?!Nov 06)' file

正则表达式说明:

> ^断言我们刚开始.
>(?!Nov 06)这个负向前瞻断言在行开始后没有字符串11月06日.如果是,则匹配边界存在于每行中的第一个字符之前.

另一种基于正则表达式的解决方案,通过PCRE动词(*SKIP)(*F)

grep -P '^Nov 06(*SKIP)(*F)|^' file

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读