简体   繁体   中英

Shell script: Replace entire line if pattern matches

I've a file with this content:

# pam_faildelay.so    
auth    required    pam_faildelay.so    delay=2000000

How can I replace an entire line if it contains pam_faildelay in it? The change should not affect comments.
I tried the following command but it updates comment.

sed -i '/pam_faildelay.so/c\auth   optional   pam_faildelay.so  delay=4000000' filename

With the above command, my file looks like this:

auth   optional   pam_faildelay.so  delay=4000000
auth   optional   pam_faildelay.so  delay=4000000

您替换不以#开头的行:

sed ' s/^[^#]*pam_faildelay\.so.*/auth   optional   pam_faildelay.so  delay=4000000/' filename

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM