extract names from LDAP long names

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:



2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com


I want to extract just the cn names :



jsmith
bjones


how can I do it?










share|improve this question









New contributor




Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    3
    down vote

    favorite












    I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:



    2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
    2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com


    I want to extract just the cn names :



    jsmith
    bjones


    how can I do it?










    share|improve this question









    New contributor




    Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:



      2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
      2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com


      I want to extract just the cn names :



      jsmith
      bjones


      how can I do it?










      share|improve this question









      New contributor




      Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have this log file which observe user actions on the network, the file contain information from LDAP, very long list like this one:



      2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
      2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com


      I want to extract just the cn names :



      jsmith
      bjones


      how can I do it?







      sed






      share|improve this question









      New contributor




      Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 46 mins ago









      msp9011

      3,61543862




      3,61543862






      New contributor




      Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      Cadice

      183




      183




      New contributor




      Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Cadice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          can be done with sed:



          sed 's/^.*cn=([^,]*).*$/1/' file

          jsmith
          bjones


          or grep



          grep -oP '(?<=cn=)[^, ]+' file


          or perl



          perl -lne '/cn=(w*),/ && print $1' file


          or cut & tr



          cut -d'=' -f2 file | tr -d 'ou,'





          share|improve this answer





























            up vote
            2
            down vote













            using sed:



            sed -e 's/.*cn=(.*),ou.*/1/' file


            using awk



            awk -F '[=,]' 'print $2' file


            or



            awk -F 'cn=|,' 'print $2' file





            share|improve this answer



























              up vote
              2
              down vote













              % < input
              2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
              2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
              % perl -nle 'print $1 if m/ cn=([^,]+)/' input
              jsmith
              bjones


              on the assumptions that a comma will not appear in the record name and that cn= do not appear elsewhere in the log






              share|improve this answer




















                Your Answer







                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "106"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );






                Cadice is a new contributor. Be nice, and check out our Code of Conduct.









                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474337%2fextract-names-from-ldap-long-names%23new-answer', 'question_page');

                );

                Post as a guest






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                2
                down vote



                accepted










                can be done with sed:



                sed 's/^.*cn=([^,]*).*$/1/' file

                jsmith
                bjones


                or grep



                grep -oP '(?<=cn=)[^, ]+' file


                or perl



                perl -lne '/cn=(w*),/ && print $1' file


                or cut & tr



                cut -d'=' -f2 file | tr -d 'ou,'





                share|improve this answer


























                  up vote
                  2
                  down vote



                  accepted










                  can be done with sed:



                  sed 's/^.*cn=([^,]*).*$/1/' file

                  jsmith
                  bjones


                  or grep



                  grep -oP '(?<=cn=)[^, ]+' file


                  or perl



                  perl -lne '/cn=(w*),/ && print $1' file


                  or cut & tr



                  cut -d'=' -f2 file | tr -d 'ou,'





                  share|improve this answer
























                    up vote
                    2
                    down vote



                    accepted







                    up vote
                    2
                    down vote



                    accepted






                    can be done with sed:



                    sed 's/^.*cn=([^,]*).*$/1/' file

                    jsmith
                    bjones


                    or grep



                    grep -oP '(?<=cn=)[^, ]+' file


                    or perl



                    perl -lne '/cn=(w*),/ && print $1' file


                    or cut & tr



                    cut -d'=' -f2 file | tr -d 'ou,'





                    share|improve this answer














                    can be done with sed:



                    sed 's/^.*cn=([^,]*).*$/1/' file

                    jsmith
                    bjones


                    or grep



                    grep -oP '(?<=cn=)[^, ]+' file


                    or perl



                    perl -lne '/cn=(w*),/ && print $1' file


                    or cut & tr



                    cut -d'=' -f2 file | tr -d 'ou,'






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 48 mins ago

























                    answered 1 hour ago









                    Goro

                    7,92653776




                    7,92653776






















                        up vote
                        2
                        down vote













                        using sed:



                        sed -e 's/.*cn=(.*),ou.*/1/' file


                        using awk



                        awk -F '[=,]' 'print $2' file


                        or



                        awk -F 'cn=|,' 'print $2' file





                        share|improve this answer
























                          up vote
                          2
                          down vote













                          using sed:



                          sed -e 's/.*cn=(.*),ou.*/1/' file


                          using awk



                          awk -F '[=,]' 'print $2' file


                          or



                          awk -F 'cn=|,' 'print $2' file





                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            using sed:



                            sed -e 's/.*cn=(.*),ou.*/1/' file


                            using awk



                            awk -F '[=,]' 'print $2' file


                            or



                            awk -F 'cn=|,' 'print $2' file





                            share|improve this answer












                            using sed:



                            sed -e 's/.*cn=(.*),ou.*/1/' file


                            using awk



                            awk -F '[=,]' 'print $2' file


                            or



                            awk -F 'cn=|,' 'print $2' file






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 1 hour ago









                            msp9011

                            3,61543862




                            3,61543862




















                                up vote
                                2
                                down vote













                                % < input
                                2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
                                2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
                                % perl -nle 'print $1 if m/ cn=([^,]+)/' input
                                jsmith
                                bjones


                                on the assumptions that a comma will not appear in the record name and that cn= do not appear elsewhere in the log






                                share|improve this answer
























                                  up vote
                                  2
                                  down vote













                                  % < input
                                  2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
                                  2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
                                  % perl -nle 'print $1 if m/ cn=([^,]+)/' input
                                  jsmith
                                  bjones


                                  on the assumptions that a comma will not appear in the record name and that cn= do not appear elsewhere in the log






                                  share|improve this answer






















                                    up vote
                                    2
                                    down vote










                                    up vote
                                    2
                                    down vote









                                    % < input
                                    2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
                                    2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
                                    % perl -nle 'print $1 if m/ cn=([^,]+)/' input
                                    jsmith
                                    bjones


                                    on the assumptions that a comma will not appear in the record name and that cn= do not appear elsewhere in the log






                                    share|improve this answer












                                    % < input
                                    2015-12-02 10:55:32Z cn=jsmith,ou=sales,dc=company,dc=com
                                    2015-12-02 10:55:54Z cn=bjones,ou=sales,dc=company,dc=com
                                    % perl -nle 'print $1 if m/ cn=([^,]+)/' input
                                    jsmith
                                    bjones


                                    on the assumptions that a comma will not appear in the record name and that cn= do not appear elsewhere in the log







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 1 hour ago









                                    thrig

                                    23k12854




                                    23k12854




















                                        Cadice is a new contributor. Be nice, and check out our Code of Conduct.









                                         

                                        draft saved


                                        draft discarded


















                                        Cadice is a new contributor. Be nice, and check out our Code of Conduct.












                                        Cadice is a new contributor. Be nice, and check out our Code of Conduct.











                                        Cadice is a new contributor. Be nice, and check out our Code of Conduct.













                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474337%2fextract-names-from-ldap-long-names%23new-answer', 'question_page');

                                        );

                                        Post as a guest













































































                                        Comments

                                        Popular posts from this blog

                                        Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                        Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                        Confectionery