grep multiple entries in openvpn.log

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











up vote
-1
down vote

favorite












i need to determine which clients tried to connect to openvpn



$ grep -e 'client[1-20]' openvpn.log | sed 's/^.*client/client/'


gives me



client16
client16
client12_pool_defined = DISABLED
client12'/var/run/openvpn.pid'
client13
client15
client16
client16


any idea how to remove duplicate entries just leaving client12, client13 and so on?







share|improve this question



















  • Does adding | uniq give you the expected output or is further sorting needed?
    – Mikael Kjær
    Apr 19 at 4:19














up vote
-1
down vote

favorite












i need to determine which clients tried to connect to openvpn



$ grep -e 'client[1-20]' openvpn.log | sed 's/^.*client/client/'


gives me



client16
client16
client12_pool_defined = DISABLED
client12'/var/run/openvpn.pid'
client13
client15
client16
client16


any idea how to remove duplicate entries just leaving client12, client13 and so on?







share|improve this question



















  • Does adding | uniq give you the expected output or is further sorting needed?
    – Mikael Kjær
    Apr 19 at 4:19












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











i need to determine which clients tried to connect to openvpn



$ grep -e 'client[1-20]' openvpn.log | sed 's/^.*client/client/'


gives me



client16
client16
client12_pool_defined = DISABLED
client12'/var/run/openvpn.pid'
client13
client15
client16
client16


any idea how to remove duplicate entries just leaving client12, client13 and so on?







share|improve this question











i need to determine which clients tried to connect to openvpn



$ grep -e 'client[1-20]' openvpn.log | sed 's/^.*client/client/'


gives me



client16
client16
client12_pool_defined = DISABLED
client12'/var/run/openvpn.pid'
client13
client15
client16
client16


any idea how to remove duplicate entries just leaving client12, client13 and so on?









share|improve this question










share|improve this question




share|improve this question









asked Apr 19 at 4:10









toxikas

6




6











  • Does adding | uniq give you the expected output or is further sorting needed?
    – Mikael Kjær
    Apr 19 at 4:19
















  • Does adding | uniq give you the expected output or is further sorting needed?
    – Mikael Kjær
    Apr 19 at 4:19















Does adding | uniq give you the expected output or is further sorting needed?
– Mikael Kjær
Apr 19 at 4:19




Does adding | uniq give you the expected output or is further sorting needed?
– Mikael Kjær
Apr 19 at 4:19










1 Answer
1






active

oldest

votes

















up vote
1
down vote













First: grep 'client[1-20]' does not look for client followed by numbers between 1 and 20. It looks for client followed by any character out of 0, 1 and 2. Using grep for a range of numbers is cumbersome and dealt with multiple times in this site. See, for example, Grep for range of numbers, Looking to grep or egrep year ranges from 1965-1996, etc.



If you want just unique entries, use sort -u or sort | uniq.



Combined, something like (assuming zero-padded numbers):



grep -Eo 'client([01][1-9]|20)' | sort -u





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
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438637%2fgrep-multiple-entries-in-openvpn-log%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    First: grep 'client[1-20]' does not look for client followed by numbers between 1 and 20. It looks for client followed by any character out of 0, 1 and 2. Using grep for a range of numbers is cumbersome and dealt with multiple times in this site. See, for example, Grep for range of numbers, Looking to grep or egrep year ranges from 1965-1996, etc.



    If you want just unique entries, use sort -u or sort | uniq.



    Combined, something like (assuming zero-padded numbers):



    grep -Eo 'client([01][1-9]|20)' | sort -u





    share|improve this answer

























      up vote
      1
      down vote













      First: grep 'client[1-20]' does not look for client followed by numbers between 1 and 20. It looks for client followed by any character out of 0, 1 and 2. Using grep for a range of numbers is cumbersome and dealt with multiple times in this site. See, for example, Grep for range of numbers, Looking to grep or egrep year ranges from 1965-1996, etc.



      If you want just unique entries, use sort -u or sort | uniq.



      Combined, something like (assuming zero-padded numbers):



      grep -Eo 'client([01][1-9]|20)' | sort -u





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        First: grep 'client[1-20]' does not look for client followed by numbers between 1 and 20. It looks for client followed by any character out of 0, 1 and 2. Using grep for a range of numbers is cumbersome and dealt with multiple times in this site. See, for example, Grep for range of numbers, Looking to grep or egrep year ranges from 1965-1996, etc.



        If you want just unique entries, use sort -u or sort | uniq.



        Combined, something like (assuming zero-padded numbers):



        grep -Eo 'client([01][1-9]|20)' | sort -u





        share|improve this answer













        First: grep 'client[1-20]' does not look for client followed by numbers between 1 and 20. It looks for client followed by any character out of 0, 1 and 2. Using grep for a range of numbers is cumbersome and dealt with multiple times in this site. See, for example, Grep for range of numbers, Looking to grep or egrep year ranges from 1965-1996, etc.



        If you want just unique entries, use sort -u or sort | uniq.



        Combined, something like (assuming zero-padded numbers):



        grep -Eo 'client([01][1-9]|20)' | sort -u






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 19 at 4:30









        Olorin

        1,15711




        1,15711






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438637%2fgrep-multiple-entries-in-openvpn-log%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?