cat sudo.txt |tr -d "[:blank:]"|grep '=.*[ALLroot].*/usr/bin/vim'
I want to track below:
=(root)NOPASSWD:/usr/bin/vim
=(ALL)NOPASSWD:/usr/bin/vim
=NOPASSWD:/usr/bin/vim
but not:
=(user)NOPASSWD:/usr/bin/find
cat sudo.txt |tr -d "[:blank:]"|grep '=.*[ALLroot].*/usr/bin/vim'
I want to track below:
=(root)NOPASSWD:/usr/bin/vim
=(ALL)NOPASSWD:/usr/bin/vim
=NOPASSWD:/usr/bin/vim
but not:
=(user)NOPASSWD:/usr/bin/find
 
    
    [ALLroot] matches A or L or r or o or t. Use (ALL|root) instead
Given:
cat sudo.txt
=(root)NOPASSWD:/usr/bin/vim
=(ALL)NOPASSWD:/usr/bin/vim
=NOPASSWD:/usr/bin/vim
=(user)NOPASSWD:/usr/bin/find
grep -E '=(\((root|ALL)\))?.*/usr/bin/vim' sudo.txt
=(root)NOPASSWD:/usr/bin/vim
=(ALL)NOPASSWD:/usr/bin/vim
=NOPASSWD:/usr/bin/vim
Explanation:
option -E : extended pattern
=                   # equal sign
(                   # start group
  \(                # opening parenthesis
    (root|ALL)      # root OR ALL
  \)                # closing parenthesis
)?                  # end group, optional
.*                  # 0 or more any character
/usr/bin/vim        # literally
 
    
    Given the data presented,
grep -E '\bNOPASSWD:/usr/bin/vim\b' sudo.txt
If that doesn't sufficiently select, please show the examples and explain the missing requirements.
