ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
if you do "grep -A1" they'd be concatenated, however there's still this trick that the 2nd lines start with a space, which will be added in the concatenation and hence result in a bad ldap record.
so, you have to use a multi-trap-rocket-science thing:
0) make a backup of your output ;-)
1) remove the leading spaces on each line
Code:
sed -i 's/^ .*/.*/g' ldap_output_file
2) grep -A1 on the cn as you stated above
3) your $test now contains concatenated output, append that to a secondary output
4) apply sed like this sed -i 's/#1#/#0#/g'; however, given that this is ldap, you'll have to move #2# to #1# I guess, but I'm tired, so I am not going into that (yet).
Another approach is to use sed and print only the even lines in "file_even" and the odd lines in "file_odd", number them and join and remove line numbers:
The first tr converts all BELs (\a) to spaces, and newlines (LF AKA \n) to BELs. The resulting output (which is a single long line) is fed to sed, which removes any BELs followed by a space or a tab (HT aka \t). Then, tr is used again to convert any BELs left to newlines. The output is saved to file output. Note that input and output must be different files; if they're the same file, you will just trash it.
Here is a wrapper around ldapsearch, which joins the continued lines together. Save it and run it just as if you would ldapsearch:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.