Hi All,
I am facing a small problem in sed. I want to insert a line in the existing file.
Existing code:
access to attr=userPassword
by self write
by * auth
access to *
by self write
by users read
by anonymous auth
Desired code:
access to attr=userPassword
by self write
by * auth
access to *
by self write
by users read
by peername.ip=127.0.0.1 read
by anonymous auth
I put the existing code in var1 and desired code in var2 and used the following sed command, but somehow it's not working for me. Can there be a easier way to do this.
Thanks Annihilannic . this works for me. But I have two such instanes of the same text in the same file and I need to make changes only in the 2nd instance.
Thanks era! But this is not working. I guess I need to find out this text first
access to attr=userPassword
by self write
by * auth
After that find out the statement "by users read" and insert this statement after it .
by peername.ip=127.0.0.1 read
So the new code would be ,
access to *
by self write
by users read
by anonymous auth
....
....
some lines here...
access to attr=userPassword
by self write
by * auth
access to *
by self write
by users read
by peername.ip=127.0.0.1 read
by anonymous auth
I'm not sure I understand. Do you mean skip down to "access to attr=userPassword" and then add the line like before, after any occurrence of "by users read"?
sed -e '1,/^access to attr=userPassword/b' \
-e '/by users read/a\''by peername.ip=127.0.0.1 read' slapd_config
I assumed "access to" is at beginning of line; taking out the ^ if that is not so should not hurt at all, though.
I am really sorry for all the confusion. Following is the part of file and I want to add a line "by peername.ip=127.0.0.1 read
" where I have made the text bold.But I want to avoid the text mareked in Red.
# access to *
# by self write
# by users read
# by anonymous auth
#
# if no access controls are present, the default policy is:
# Allow read by all
#
# rootdn can always write!
######################################################################
#leave at default of 500
#sizelimit 200
# acl ################################################################
#defaultaccess search
access to attr=userPassword
by self write
by * auth
access to *
by self write
by users read
by anonymous auth
As such, the solution I posted appears to also work. It just passes through anything up through the l"access to attr=userPassword" line and then performs the addition of "by peername etc" after any match on "by users read".