Find animal-060, animal-061, animal-062 …, animal-069 in .txt using linux terminal












1















I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]' animallist.txt



Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.










share|improve this question

























  • Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^

    – Joe Th
    Nov 15 '18 at 1:09













  • stackoverflow.com/editing-help - does that help?

    – tink
    Nov 15 '18 at 1:22
















1















I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]' animallist.txt



Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.










share|improve this question

























  • Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^

    – Joe Th
    Nov 15 '18 at 1:09













  • stackoverflow.com/editing-help - does that help?

    – tink
    Nov 15 '18 at 1:22














1












1








1








I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]' animallist.txt



Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.










share|improve this question
















I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]' animallist.txt



Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.







regex linux terminal grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 0:50









tink

6,69332634




6,69332634










asked Nov 15 '18 at 0:33









Joe ThJoe Th

102




102













  • Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^

    – Joe Th
    Nov 15 '18 at 1:09













  • stackoverflow.com/editing-help - does that help?

    – tink
    Nov 15 '18 at 1:22



















  • Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^

    – Joe Th
    Nov 15 '18 at 1:09













  • stackoverflow.com/editing-help - does that help?

    – tink
    Nov 15 '18 at 1:22

















Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^

– Joe Th
Nov 15 '18 at 1:09







Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^

– Joe Th
Nov 15 '18 at 1:09















stackoverflow.com/editing-help - does that help?

– tink
Nov 15 '18 at 1:22





stackoverflow.com/editing-help - does that help?

– tink
Nov 15 '18 at 1:22












3 Answers
3






active

oldest

votes


















0














You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with * or + etc. In your example, [60-69] is the same as [690-6] which will match any single 6, 9, or charater in the range 0-6.
To find the numbers between 60 and 69, we must look at the numbers as a string.



Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j].



Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:



animal-06[0-9]


As a complete command, this would be:



grep -E 'animal-06[0-9]' animallist.txt





share|improve this answer































    0














    Yes if you will use grep -E 'animal-06[0-9]' animallist.txt it will work






    share|improve this answer































      -1














      grep -E 'animal-06[0-9]' animallist.txt 


      And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        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',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310818%2ffind-animal-060-animal-061-animal-062-animal-069-in-txt-using-linux-term%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with * or + etc. In your example, [60-69] is the same as [690-6] which will match any single 6, 9, or charater in the range 0-6.
        To find the numbers between 60 and 69, we must look at the numbers as a string.



        Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j].



        Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:



        animal-06[0-9]


        As a complete command, this would be:



        grep -E 'animal-06[0-9]' animallist.txt





        share|improve this answer




























          0














          You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with * or + etc. In your example, [60-69] is the same as [690-6] which will match any single 6, 9, or charater in the range 0-6.
          To find the numbers between 60 and 69, we must look at the numbers as a string.



          Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j].



          Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:



          animal-06[0-9]


          As a complete command, this would be:



          grep -E 'animal-06[0-9]' animallist.txt





          share|improve this answer


























            0












            0








            0







            You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with * or + etc. In your example, [60-69] is the same as [690-6] which will match any single 6, 9, or charater in the range 0-6.
            To find the numbers between 60 and 69, we must look at the numbers as a string.



            Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j].



            Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:



            animal-06[0-9]


            As a complete command, this would be:



            grep -E 'animal-06[0-9]' animallist.txt





            share|improve this answer













            You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with * or + etc. In your example, [60-69] is the same as [690-6] which will match any single 6, 9, or charater in the range 0-6.
            To find the numbers between 60 and 69, we must look at the numbers as a string.



            Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j].



            Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:



            animal-06[0-9]


            As a complete command, this would be:



            grep -E 'animal-06[0-9]' animallist.txt






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 '18 at 0:49









            Kind StrangerKind Stranger

            1,054718




            1,054718

























                0














                Yes if you will use grep -E 'animal-06[0-9]' animallist.txt it will work






                share|improve this answer




























                  0














                  Yes if you will use grep -E 'animal-06[0-9]' animallist.txt it will work






                  share|improve this answer


























                    0












                    0








                    0







                    Yes if you will use grep -E 'animal-06[0-9]' animallist.txt it will work






                    share|improve this answer













                    Yes if you will use grep -E 'animal-06[0-9]' animallist.txt it will work







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 15 '18 at 1:16









                    Salvatore CaramazzaSalvatore Caramazza

                    11




                    11























                        -1














                        grep -E 'animal-06[0-9]' animallist.txt 


                        And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.






                        share|improve this answer




























                          -1














                          grep -E 'animal-06[0-9]' animallist.txt 


                          And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.






                          share|improve this answer


























                            -1












                            -1








                            -1







                            grep -E 'animal-06[0-9]' animallist.txt 


                            And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.






                            share|improve this answer













                            grep -E 'animal-06[0-9]' animallist.txt 


                            And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 15 '18 at 0:49









                            tinktink

                            6,69332634




                            6,69332634






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310818%2ffind-animal-060-animal-061-animal-062-animal-069-in-txt-using-linux-term%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Xamarin.iOS Cant Deploy on Iphone

                                Glorious Revolution

                                Dulmage-Mendelsohn matrix decomposition in Python