Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    [SOLVED] Vim: Find line and insert line below it

    I've been googling and fooling with this for quite some time, and although it seems simple enough, I haven't been able to figure it out.

    I've got data that looks like:

    dn: uid=bob$,ou=Computers,dc=null,dc=com

    I need to find all lines that have "ou=Computers". and go to the end of the line, insert a new line, and put in "objectClass: account" , so the end result would be:

    dn: uid=bob$,ou=Computers,dc=null,dc=com
    objectClass: account

    every time I try to do this I end up creating a new line at the end of "ou=Computers" and bringing the rest of the line down to the new line.

    Could someone please guide me to the correct way of doing this?


  2. #2
    I would do that with sed but if you need to accomplish it with vim run this command:
    :%s/^\(dn: uid=\w\+\$,ou=\w\+,dc=\w\+,dc=\w\+\m\)$/\1\robjectClass: account/
    If needed, customize the regular expression.
    Refining Linux Advent calendar: 24 Outstanding ZSH Gems

  3. #3
    You are the man!

    That worked perfectly, now my LDAP loads fine

    My eyes went crossed reading it, but it worked great, thanks again!

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts