Find the answer to your Linux question:
Results 1 to 3 of 3
hello community! i have a text file (it`s a ldif export), and i would like to grep out the dn. the line with the dn starts with "dn:". no problem ...
  1. #1
    Iko
    Iko is offline
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2

    Question remove leading space and join previous line

    hello community!

    i have a text file (it`s a ldif export), and i would like to grep out the dn. the line with the dn starts with "dn:". no problem so far to grep for this pattern.
    but the ldif export makes a line break after 76 characters, and continues the next line with a "space" character.

    since i need the full dn, i need a way to:
    1) search for this lines which start with a leading "space"
    2) remove this "space"
    3) and finally join the line which had the space, with the previous line

    i have tried several ways with sed, awk, tr, ... but since i´m quite new to this topics i dont get it solved. does anyone here have a hint for me, how to do this task?

    thanks in advance,
    iko

  2. #2
    Just Joined!
    Join Date
    Nov 2006
    Posts
    2

    A Solution

    Perl seems like an obvious tool for this. Here is a rough hack that may get you started. Put this on the command line:

    Code:
    perl -ne 'use feature "state"; state $join_it=0; if ($join_it==1) { if (s/^ //) { print } else { print "\n" }; $join_it=0 }; if (/^dn:/) { chomp; print; $join_it=1 }' dn_file
    p.s. I'm not a programmer, so forgive any bad style.

  3. #3
    Iko
    Iko is offline
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2
    ty vamped1.

    in the meantime i got a solution which is more compact and is exactly what i need.
    for everyones interest:
    sed -e :a -e '$!N;s/\n //;ta' -e 'P;D' filename

    br, iko

Posting Permissions

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