![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed pattern matching | ravi_rn | Shell Programming and Scripting | 4 | 04-20-2009 07:24 AM |
| counting the lines matching a pattern, in between two pattern, and generate a tab | d.chauliac | Shell Programming and Scripting | 4 | 03-19-2009 01:30 PM |
| search a pattern and if pattern found insert new pattern at the begining | pitagi | Shell Programming and Scripting | 7 | 02-12-2009 10:27 PM |
| comment/delete a particular pattern starting from second line of the matching pattern | imas | Shell Programming and Scripting | 4 | 10-13-2008 02:37 AM |
| pattern matching | larryase | UNIX for Dummies Questions & Answers | 3 | 11-22-2004 06:54 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
sed - matching pattern one but not pattern two
All,
I have the following file: -------------------------------------- # # /etc/pam.d/common-password - password-related modules common to all services # # This file is included from other service-specific PAM config files, # and should contain a list of modules that define the services to be # used to change user passwords. The default is pam_unix2 in combination # with pam_pwcheck. # The "nullok" option allows users to change an empty password, else # empty passwords are treated as locked accounts. # # To enable Blowfish or MD5 passwords, you should edit # /etc/default/passwd. # # Alternate strength checking for passwords should be configured # in /etc/security/pam_pwcheck.conf. # # pam_make can be used to rebuild NIS maps after password change. # password required pam_passwdqc.so retry=5 ask_oldauthok min=disabled,8,8,8,8 passphrase=0 random=0 force=everyone password required pam_pwcheck.so nullok password required pam_unix2.so nullok use_authtok #password required pam_make.so /var/yp -------------------------------------------------------------------- What I would like to do is generate a sed command that will: Add "use_first_pass" to a line if the line contains "pam_unix2.so" but the line does *not* contain "use_first_pass". The remainer of the file should be left alone. I can generate the logic with: a regex of: (.*pam_unix2\.so.*) (?!.*use_first_pass.*) I am having trouble translating that into a sed expression. Thanks, -Robert |
|
||||
|
if you can use Python
Code:
for line in open("file"):
line=line.strip()
if "pam_unix2.so" in line and not "use_first_pass" in line:
print "use_first_pass " + line
else:
print line
Code:
import fileinput
for line in fileinput.FileInput("file",inplace=1):
line=line.strip()
if "pam_unix2.so" in line and not "use_first_pass" in line:
print "use_first_pass " + line
else:
print line
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|