Checking if the end of each line in the file is ending with a letter followed by 8 digits number

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








up vote
2
down vote

favorite












I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:



Nc1nc2cc3OCCOc3cc2s1 A10000001 
CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003


There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?



Thanks!







share|improve this question
























    up vote
    2
    down vote

    favorite












    I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:



    Nc1nc2cc3OCCOc3cc2s1 A10000001 
    CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
    CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003


    There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?



    Thanks!







    share|improve this question






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:



      Nc1nc2cc3OCCOc3cc2s1 A10000001 
      CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
      CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003


      There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?



      Thanks!







      share|improve this question












      I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:



      Nc1nc2cc3OCCOc3cc2s1 A10000001 
      CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
      CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003


      There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?



      Thanks!









      share|improve this question











      share|improve this question




      share|improve this question










      asked May 14 at 14:30









      sergio

      565




      565




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          You can use grep to get the lines that don't follow the rule:



          grep -v ' [[:upper:]][0-9]8$' file*


          • space matches itself


          • [[:upper:]] is matched by any uppercase letter


          • [0-9] matches a digit


          • 8 is a "quantifier", it means the preceding construct must be repeated 8 times


          • $ matches at the end of line


          • -v shows the lines that are not matched





          share|improve this answer


















          • 1




            "...get the lines that don't follow the rule" ? Wouldn't that also need -v flag for grep -v to match lines that don't follow the pattern ?
            – Sergiy Kolodyazhnyy
            May 14 at 15:56










          • you are right, when I add -v then script applies to all lines, without it, it just greps some of them..
            – sergio
            May 15 at 1:26

















          up vote
          0
          down vote













          you could grep with a perl regexp:



          grep -P ' [a-zA-Z]1[0-9]8$'


          -P : for perl Regular expression



          : the regexp starts with a space, because you want a space before the uppercase letter



          [a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)



          [0-9]8 : exactly 8 numeric chars



          $ : end of line



          If you want to display the lines that does not match the pattern, just add the -v option to the grep command.



          If you want to display lines numbers, add the -n option.



          grep -Pvn ' [a-zA-Z]1[0-9]8$'





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            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: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1036148%2fchecking-if-the-end-of-each-line-in-the-file-is-ending-with-a-letter-followed-by%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote













            You can use grep to get the lines that don't follow the rule:



            grep -v ' [[:upper:]][0-9]8$' file*


            • space matches itself


            • [[:upper:]] is matched by any uppercase letter


            • [0-9] matches a digit


            • 8 is a "quantifier", it means the preceding construct must be repeated 8 times


            • $ matches at the end of line


            • -v shows the lines that are not matched





            share|improve this answer


















            • 1




              "...get the lines that don't follow the rule" ? Wouldn't that also need -v flag for grep -v to match lines that don't follow the pattern ?
              – Sergiy Kolodyazhnyy
              May 14 at 15:56










            • you are right, when I add -v then script applies to all lines, without it, it just greps some of them..
              – sergio
              May 15 at 1:26














            up vote
            3
            down vote













            You can use grep to get the lines that don't follow the rule:



            grep -v ' [[:upper:]][0-9]8$' file*


            • space matches itself


            • [[:upper:]] is matched by any uppercase letter


            • [0-9] matches a digit


            • 8 is a "quantifier", it means the preceding construct must be repeated 8 times


            • $ matches at the end of line


            • -v shows the lines that are not matched





            share|improve this answer


















            • 1




              "...get the lines that don't follow the rule" ? Wouldn't that also need -v flag for grep -v to match lines that don't follow the pattern ?
              – Sergiy Kolodyazhnyy
              May 14 at 15:56










            • you are right, when I add -v then script applies to all lines, without it, it just greps some of them..
              – sergio
              May 15 at 1:26












            up vote
            3
            down vote










            up vote
            3
            down vote









            You can use grep to get the lines that don't follow the rule:



            grep -v ' [[:upper:]][0-9]8$' file*


            • space matches itself


            • [[:upper:]] is matched by any uppercase letter


            • [0-9] matches a digit


            • 8 is a "quantifier", it means the preceding construct must be repeated 8 times


            • $ matches at the end of line


            • -v shows the lines that are not matched





            share|improve this answer














            You can use grep to get the lines that don't follow the rule:



            grep -v ' [[:upper:]][0-9]8$' file*


            • space matches itself


            • [[:upper:]] is matched by any uppercase letter


            • [0-9] matches a digit


            • 8 is a "quantifier", it means the preceding construct must be repeated 8 times


            • $ matches at the end of line


            • -v shows the lines that are not matched






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 15 at 10:05

























            answered May 14 at 14:54









            choroba

            5,89411726




            5,89411726







            • 1




              "...get the lines that don't follow the rule" ? Wouldn't that also need -v flag for grep -v to match lines that don't follow the pattern ?
              – Sergiy Kolodyazhnyy
              May 14 at 15:56










            • you are right, when I add -v then script applies to all lines, without it, it just greps some of them..
              – sergio
              May 15 at 1:26












            • 1




              "...get the lines that don't follow the rule" ? Wouldn't that also need -v flag for grep -v to match lines that don't follow the pattern ?
              – Sergiy Kolodyazhnyy
              May 14 at 15:56










            • you are right, when I add -v then script applies to all lines, without it, it just greps some of them..
              – sergio
              May 15 at 1:26







            1




            1




            "...get the lines that don't follow the rule" ? Wouldn't that also need -v flag for grep -v to match lines that don't follow the pattern ?
            – Sergiy Kolodyazhnyy
            May 14 at 15:56




            "...get the lines that don't follow the rule" ? Wouldn't that also need -v flag for grep -v to match lines that don't follow the pattern ?
            – Sergiy Kolodyazhnyy
            May 14 at 15:56












            you are right, when I add -v then script applies to all lines, without it, it just greps some of them..
            – sergio
            May 15 at 1:26




            you are right, when I add -v then script applies to all lines, without it, it just greps some of them..
            – sergio
            May 15 at 1:26












            up vote
            0
            down vote













            you could grep with a perl regexp:



            grep -P ' [a-zA-Z]1[0-9]8$'


            -P : for perl Regular expression



            : the regexp starts with a space, because you want a space before the uppercase letter



            [a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)



            [0-9]8 : exactly 8 numeric chars



            $ : end of line



            If you want to display the lines that does not match the pattern, just add the -v option to the grep command.



            If you want to display lines numbers, add the -n option.



            grep -Pvn ' [a-zA-Z]1[0-9]8$'





            share|improve this answer
























              up vote
              0
              down vote













              you could grep with a perl regexp:



              grep -P ' [a-zA-Z]1[0-9]8$'


              -P : for perl Regular expression



              : the regexp starts with a space, because you want a space before the uppercase letter



              [a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)



              [0-9]8 : exactly 8 numeric chars



              $ : end of line



              If you want to display the lines that does not match the pattern, just add the -v option to the grep command.



              If you want to display lines numbers, add the -n option.



              grep -Pvn ' [a-zA-Z]1[0-9]8$'





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                you could grep with a perl regexp:



                grep -P ' [a-zA-Z]1[0-9]8$'


                -P : for perl Regular expression



                : the regexp starts with a space, because you want a space before the uppercase letter



                [a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)



                [0-9]8 : exactly 8 numeric chars



                $ : end of line



                If you want to display the lines that does not match the pattern, just add the -v option to the grep command.



                If you want to display lines numbers, add the -n option.



                grep -Pvn ' [a-zA-Z]1[0-9]8$'





                share|improve this answer












                you could grep with a perl regexp:



                grep -P ' [a-zA-Z]1[0-9]8$'


                -P : for perl Regular expression



                : the regexp starts with a space, because you want a space before the uppercase letter



                [a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)



                [0-9]8 : exactly 8 numeric chars



                $ : end of line



                If you want to display the lines that does not match the pattern, just add the -v option to the grep command.



                If you want to display lines numbers, add the -n option.



                grep -Pvn ' [a-zA-Z]1[0-9]8$'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 14 at 15:01









                cmak.fr

                1,539918




                1,539918






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036148%2fchecking-if-the-end-of-each-line-in-the-file-is-ending-with-a-letter-followed-by%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Unable to execute new pre-installation script (/var/lib/dpkg/tmp.ci/preinst)

                    Running the scala interactive shell from the command line

                    Do not install recommended packages of dependencies