Print the lines that only with all consecutive repeated characters

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











up vote
0
down vote

favorite












I have a text file and I want to print only the lines that have all their characters are consecutively reapeated at least two times or more.
FOR EXAMPLE THE INPUT:



11
AAA
555227777
BBhh@@222
baabbb
1112
212211
baa
22333445
322113


 The output should be:



11
AAA
555227777
BBhh@@222


 The output contains only these four lines because  they have only consecutively duplicate characters in order.



I have tried this code



grep '(^| )([   ])21($| )' INFILE


But its not working exactly.










share|improve this question























  • a revert answer to your previous question is required only here. All your questions are in same category, so you exercise something?
    – sddgob
    17 mins ago















up vote
0
down vote

favorite












I have a text file and I want to print only the lines that have all their characters are consecutively reapeated at least two times or more.
FOR EXAMPLE THE INPUT:



11
AAA
555227777
BBhh@@222
baabbb
1112
212211
baa
22333445
322113


 The output should be:



11
AAA
555227777
BBhh@@222


 The output contains only these four lines because  they have only consecutively duplicate characters in order.



I have tried this code



grep '(^| )([   ])21($| )' INFILE


But its not working exactly.










share|improve this question























  • a revert answer to your previous question is required only here. All your questions are in same category, so you exercise something?
    – sddgob
    17 mins ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a text file and I want to print only the lines that have all their characters are consecutively reapeated at least two times or more.
FOR EXAMPLE THE INPUT:



11
AAA
555227777
BBhh@@222
baabbb
1112
212211
baa
22333445
322113


 The output should be:



11
AAA
555227777
BBhh@@222


 The output contains only these four lines because  they have only consecutively duplicate characters in order.



I have tried this code



grep '(^| )([   ])21($| )' INFILE


But its not working exactly.










share|improve this question















I have a text file and I want to print only the lines that have all their characters are consecutively reapeated at least two times or more.
FOR EXAMPLE THE INPUT:



11
AAA
555227777
BBhh@@222
baabbb
1112
212211
baa
22333445
322113


 The output should be:



11
AAA
555227777
BBhh@@222


 The output contains only these four lines because  they have only consecutively duplicate characters in order.



I have tried this code



grep '(^| )([   ])21($| )' INFILE


But its not working exactly.







text-processing grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 23 mins ago









Jeff Schaller

34.2k851113




34.2k851113










asked 28 mins ago









Ahmed

404




404











  • a revert answer to your previous question is required only here. All your questions are in same category, so you exercise something?
    – sddgob
    17 mins ago

















  • a revert answer to your previous question is required only here. All your questions are in same category, so you exercise something?
    – sddgob
    17 mins ago
















a revert answer to your previous question is required only here. All your questions are in same category, so you exercise something?
– sddgob
17 mins ago





a revert answer to your previous question is required only here. All your questions are in same category, so you exercise something?
– sddgob
17 mins ago











1 Answer
1






active

oldest

votes

















up vote
0
down vote













You could invert this answer:



sed -n -e '/^(.)11*$/p' < input > output


... or the grep variation:



grep '^(.)11*$' < input > output





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%2f476379%2fprint-the-lines-that-only-with-all-consecutive-repeated-characters%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
    0
    down vote













    You could invert this answer:



    sed -n -e '/^(.)11*$/p' < input > output


    ... or the grep variation:



    grep '^(.)11*$' < input > output





    share|improve this answer
























      up vote
      0
      down vote













      You could invert this answer:



      sed -n -e '/^(.)11*$/p' < input > output


      ... or the grep variation:



      grep '^(.)11*$' < input > output





      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        You could invert this answer:



        sed -n -e '/^(.)11*$/p' < input > output


        ... or the grep variation:



        grep '^(.)11*$' < input > output





        share|improve this answer












        You could invert this answer:



        sed -n -e '/^(.)11*$/p' < input > output


        ... or the grep variation:



        grep '^(.)11*$' < input > output






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 19 mins ago









        Jeff Schaller

        34.2k851113




        34.2k851113



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476379%2fprint-the-lines-that-only-with-all-consecutive-repeated-characters%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)