This is a job for sed
:
$ sed -r 's/^#(.*sufficient\s+pam_wheel\.so trust use_uid.*)/\1/' file
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
auth sufficient pam_wheel.so trust use_uid
auth include system-auth
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
Regexplanation:
s/ # Substitute
^# # A line starting with a #
( # Start capture group
.* # Followed by anything
sufficient # Followed by the word sufficient
\s+ # Followed by whitespace
pam_wheel\.so trust use_uid # Followed by the literal string (escaped .)
.* # Followed by anything
) # Stop capture group
/ # Replace with
\1 # The first capture group
So effectively we are matching lines starting with #
containing the string sufficient\s+pam_wheel.so trust use_uid
and removing the #
Notes: the -r
flag is for extended regexp, it might be -E
for your version of sed
so check the man
.
If you want to store the changes back to the file
use the -i
option:
$ sed -ri 's/^#(.*sufficient\s+pam_wheel\.so trust use_uid.*)/\1/' file
If the column aligment is important then capture up to sufficient
and after it so you get 2 capture groups and replace with \1 \2
.
$ sed -r 's/^#(.*)(sufficient\s+pam_wheel\.so trust use_uid.*)/\1 \2/' file
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
auth sufficient pam_wheel.so trust use_uid
auth include system-auth
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
Edit:
Replace the string AllowUsers support admin
with #AllowUsers support admin
:
$ sed -r 's/^(AllowUsers support admin.*)/#\1/' file
#AllowUsers support admin
$ sed -r 's/^(DeniedUsers root.*)/#\1/' file
#DeniedUsers root