gpt4 book ai didi

linux - Grep 包含 string1 或不包含 string2 的行

转载 作者:太空宇宙 更新时间:2023-11-04 05:48:53 27 4
gpt4 key购买 nike

我需要将行从 stdout 重定向到文件,但仅限于那些包含某些 string1 或不包含某些 string2 的行。我怎样才能做到这一点?我只知道如何单独执行此操作(包含 string1 的行或不包含 string2 的行)。它不一定是 grep,只是我可以在终端管道中使用的东西。

最佳答案

Perl 来救援!

perl -ne 'print if /string1/ || ! /string2/' < file
  • -n 逐行读取输入
  • /string1/ 是正则表达式匹配
  • || 表示“或”,! 表示“非”

关于linux - Grep 包含 string1 或不包含 string2 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47932299/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com