RenMcCourtey has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'd like to seek your help on tedious task I'm fighting today. I need to reformat ldapsearch output to acceptable form, and I'd prefer to do that inline with one command. Originally I had complex piped steps of sed and grep and then I realized perl could do that better but I don't know how. Basically I'd like to drop empty or ^dn: lines and merge some other lines together while trimming them. Source looks like this:
And the result should go like this:dn: distinguished_name1 cn: common_name1 orclnetdescstring: complex_address_line1 dn: distinguished_name2 cn: common_name2 orclnetdescstring: complex_address_line2 dn: distinguished_name3 cn: common_name3 orclnetdescstring: complex_address_line3
Now I believed this one liner, which I completed with help here would do that: perl -p0e 's/\n^$|\n^dn:*$//mg','s/cn: //g','s/\norclnetdescstring: /=/g' nejms.txt but it doesn't. And as it's getting more complex, I can't see the errors and maybe I'd be better with original sequence of more generic commands, I'm not sure.common_name1=complex_address_line1 common_name2=complex_address_line2 common_name3=complex_address_line3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reformat command output inline
by choroba (Cardinal) on Jun 29, 2016 at 13:04 UTC | |
by RenMcCourtey (Acolyte) on Jun 29, 2016 at 13:48 UTC | |
by choroba (Cardinal) on Jun 29, 2016 at 13:56 UTC | |
by RenMcCourtey (Acolyte) on Jun 29, 2016 at 14:10 UTC | |
|
Re: Reformat command output inline
by haukex (Archbishop) on Jun 29, 2016 at 13:13 UTC | |
by RenMcCourtey (Acolyte) on Jun 29, 2016 at 13:51 UTC | |
|
Re: Reformat command output inline
by kcott (Archbishop) on Jun 30, 2016 at 02:33 UTC |