Linux

如何在 linux 中模擬舊的 unix grep -S strict 功能

  • August 22, 2015

我正在搜尋命令的輸出,我希望只返回特定的、嚴格的結果。

我記得 grep 的一些迭代有一個嚴格的選項-s/ --strict

例如,grep -s bytes只會返回提及“字節”一詞的條目,而不是每個包含字節的詞,如“兆字節”、“千字節”等。

   -w, --word-regexp
          Select  only those lines containing matches that form whole
          words.  The test is that the matching
          substring must either be at the beginning of the line, or 
          preceded  by  a  non-word  constituent
          character.   Similarly,  it  must be either at the end of the
          line or followed by a non-word con-
          stituent character.  Word-constituent characters are
          letters, digits, and the underscore.

引用自:https://serverfault.com/questions/9917