How to print specified lines only?

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











up vote
-1
down vote

favorite












I want to specify the output from text file in one command as below:



1-Print all lines that have all consecutive duplicates characters.
2-Print all lines with all consecutively repeated characters except the last one or the last two characters in the same line.
3-Print all lines with all consecutively repeated characters except the first one or the first two characters in the same line.
Example: 11122323 1112266 44778 223334456 6778811 845511 3357788



The output should be



1112266 >>>>> All repeated characters.
44778 >>>>> All repeated except the last character.
223334456 >>> All repeated except the last two characters
6778811 >>>> All repeated except the first character.
845511 >>>> All repeated except the first two characters.
Non consecutively repeating characters are allowed, but only if 1st or 2nd from start or end of a line. First line excluded becuse it has #3 is not consecutively repeated.



I have tried this command but it works even with not con
secutive duplicates characters.



awk '
split ("", N) # delete N array
P = 1 # reset boolean L used for print decision
L = length
for (i=1; i<=L; i++) N[substr($0, i, 1)]+=((i<3)


P # print if non-duplicate chars exist only at margins
' file










share|improve this question



























    up vote
    -1
    down vote

    favorite












    I want to specify the output from text file in one command as below:



    1-Print all lines that have all consecutive duplicates characters.
    2-Print all lines with all consecutively repeated characters except the last one or the last two characters in the same line.
    3-Print all lines with all consecutively repeated characters except the first one or the first two characters in the same line.
    Example: 11122323 1112266 44778 223334456 6778811 845511 3357788



    The output should be



    1112266 >>>>> All repeated characters.
    44778 >>>>> All repeated except the last character.
    223334456 >>> All repeated except the last two characters
    6778811 >>>> All repeated except the first character.
    845511 >>>> All repeated except the first two characters.
    Non consecutively repeating characters are allowed, but only if 1st or 2nd from start or end of a line. First line excluded becuse it has #3 is not consecutively repeated.



    I have tried this command but it works even with not con
    secutive duplicates characters.



    awk '
    split ("", N) # delete N array
    P = 1 # reset boolean L used for print decision
    L = length
    for (i=1; i<=L; i++) N[substr($0, i, 1)]+=((i<3)


    P # print if non-duplicate chars exist only at margins
    ' file










    share|improve this question

























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I want to specify the output from text file in one command as below:



      1-Print all lines that have all consecutive duplicates characters.
      2-Print all lines with all consecutively repeated characters except the last one or the last two characters in the same line.
      3-Print all lines with all consecutively repeated characters except the first one or the first two characters in the same line.
      Example: 11122323 1112266 44778 223334456 6778811 845511 3357788



      The output should be



      1112266 >>>>> All repeated characters.
      44778 >>>>> All repeated except the last character.
      223334456 >>> All repeated except the last two characters
      6778811 >>>> All repeated except the first character.
      845511 >>>> All repeated except the first two characters.
      Non consecutively repeating characters are allowed, but only if 1st or 2nd from start or end of a line. First line excluded becuse it has #3 is not consecutively repeated.



      I have tried this command but it works even with not con
      secutive duplicates characters.



      awk '
      split ("", N) # delete N array
      P = 1 # reset boolean L used for print decision
      L = length
      for (i=1; i<=L; i++) N[substr($0, i, 1)]+=((i<3)


      P # print if non-duplicate chars exist only at margins
      ' file










      share|improve this question















      I want to specify the output from text file in one command as below:



      1-Print all lines that have all consecutive duplicates characters.
      2-Print all lines with all consecutively repeated characters except the last one or the last two characters in the same line.
      3-Print all lines with all consecutively repeated characters except the first one or the first two characters in the same line.
      Example: 11122323 1112266 44778 223334456 6778811 845511 3357788



      The output should be



      1112266 >>>>> All repeated characters.
      44778 >>>>> All repeated except the last character.
      223334456 >>> All repeated except the last two characters
      6778811 >>>> All repeated except the first character.
      845511 >>>> All repeated except the first two characters.
      Non consecutively repeating characters are allowed, but only if 1st or 2nd from start or end of a line. First line excluded becuse it has #3 is not consecutively repeated.



      I have tried this command but it works even with not con
      secutive duplicates characters.



      awk '
      split ("", N) # delete N array
      P = 1 # reset boolean L used for print decision
      L = length
      for (i=1; i<=L; i++) N[substr($0, i, 1)]+=((i<3)


      P # print if non-duplicate chars exist only at margins
      ' file







      command-line






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 15 mins ago

























      asked 21 mins ago









      Ahmed

      565




      565

























          active

          oldest

          votes











          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%2f477112%2fhow-to-print-specified-lines-only%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477112%2fhow-to-print-specified-lines-only%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)