Unix Command to List files containing string but *NOT* containing another string

后端 未结 6 1739
春和景丽
春和景丽 2021-01-30 22:01

How do I recursively view a list of files that has one string and specifically doesn\'t have another string? Also, I mean to evaluate the text of the files, not the filenames.

6条回答
  •  长情又很酷
    2021-01-30 22:37

    To match string A and exclude strings B & C being present in the same line I use, and quotes to allow search string to contain a space

    grep -r  | grep -v -e  -e "" | awk -F ':' '{print $1}'
    

    Explanation: grep -r recursively filters all lines matching in output format

    filename: line

    To exclude (grep -v) from those lines the ones that also contain either -e string B or -e string C. awk is used to print only the first field (the filename) using the colon as fieldseparator -F

提交回复
热议问题