I need to add kernel parameters to lines not already containing them. (Don't want to add it to all lines in case it's already there.)
I've built this awk command to do it in buffer, but having trouble getting it into the file itself since awk lacks the ability to edit in place like sed. (However I can't figure out how to do this type of match with sed.)
awk '/\tkernel/&&!/audit=1/ { print $0" audit=1"; }' /etc/grub.conf
This looks for lines matching "kernel" and NOT "audit=1" (appending " audit=1" as necessary.)
Tagged as sed/awk, but open to other suggestions.
Using sed:
sed -i '/kernel/{/audit=1/!s/$/ audit=1/}' /etc/grub.conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With