Using Grep on txt file to find 7 letter words that start with the same letter












1















grep -i "^(.).*1$" sowpods.txt > output.txt


I'm using a scrabble words list I downloaded named "sowpods.txt" and I am trying to use grep to find all of the 7 letter words in the file that start and end with the same letter .The line I have now is giving me a backreference error so I tried using online guides but they were insanely confusing. Could someone help me do this? Thanks!



I'm also on a mac and am using the default terminal.










share|improve this question




















  • 2





    Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, please take a look at: How does deleting work?

    – iBot
    Feb 12 at 21:22
















1















grep -i "^(.).*1$" sowpods.txt > output.txt


I'm using a scrabble words list I downloaded named "sowpods.txt" and I am trying to use grep to find all of the 7 letter words in the file that start and end with the same letter .The line I have now is giving me a backreference error so I tried using online guides but they were insanely confusing. Could someone help me do this? Thanks!



I'm also on a mac and am using the default terminal.










share|improve this question




















  • 2





    Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, please take a look at: How does deleting work?

    – iBot
    Feb 12 at 21:22














1












1








1








grep -i "^(.).*1$" sowpods.txt > output.txt


I'm using a scrabble words list I downloaded named "sowpods.txt" and I am trying to use grep to find all of the 7 letter words in the file that start and end with the same letter .The line I have now is giving me a backreference error so I tried using online guides but they were insanely confusing. Could someone help me do this? Thanks!



I'm also on a mac and am using the default terminal.










share|improve this question
















grep -i "^(.).*1$" sowpods.txt > output.txt


I'm using a scrabble words list I downloaded named "sowpods.txt" and I am trying to use grep to find all of the 7 letter words in the file that start and end with the same letter .The line I have now is giving me a backreference error so I tried using online guides but they were insanely confusing. Could someone help me do this? Thanks!



I'm also on a mac and am using the default terminal.







command-line bash grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 12 at 21:49









Kamil Maciorowski

28.6k156187




28.6k156187










asked Sep 10 '18 at 13:53









Kappa123Kappa123

62




62








  • 2





    Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, please take a look at: How does deleting work?

    – iBot
    Feb 12 at 21:22














  • 2





    Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, please take a look at: How does deleting work?

    – iBot
    Feb 12 at 21:22








2




2





Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, please take a look at: How does deleting work?

– iBot
Feb 12 at 21:22





Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, please take a look at: How does deleting work?

– iBot
Feb 12 at 21:22










2 Answers
2






active

oldest

votes


















2














This will work as an extended regular expression. You need grep -E:



grep -E -i "^(.).*1$"


To match 7-letter words you need to replace * with {5}:



grep -E -i "^(.).{5}1$"





share|improve this answer
























  • I'm a fan of the -x flag: grep -Eix "(.).{5}1"

    – Jim L.
    Jan 30 at 22:46



















2














If you want to use basic regular expression (without option -E), you need a backslash before the opening and closing brackets:



grep -i '^(.).{5}1$' file


Note that it's good idea to use single quote in your grep regex in order to avoid shell parameter expansion.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    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%2fsuperuser.com%2fquestions%2f1356890%2fusing-grep-on-txt-file-to-find-7-letter-words-that-start-with-the-same-letter%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    This will work as an extended regular expression. You need grep -E:



    grep -E -i "^(.).*1$"


    To match 7-letter words you need to replace * with {5}:



    grep -E -i "^(.).{5}1$"





    share|improve this answer
























    • I'm a fan of the -x flag: grep -Eix "(.).{5}1"

      – Jim L.
      Jan 30 at 22:46
















    2














    This will work as an extended regular expression. You need grep -E:



    grep -E -i "^(.).*1$"


    To match 7-letter words you need to replace * with {5}:



    grep -E -i "^(.).{5}1$"





    share|improve this answer
























    • I'm a fan of the -x flag: grep -Eix "(.).{5}1"

      – Jim L.
      Jan 30 at 22:46














    2












    2








    2







    This will work as an extended regular expression. You need grep -E:



    grep -E -i "^(.).*1$"


    To match 7-letter words you need to replace * with {5}:



    grep -E -i "^(.).{5}1$"





    share|improve this answer













    This will work as an extended regular expression. You need grep -E:



    grep -E -i "^(.).*1$"


    To match 7-letter words you need to replace * with {5}:



    grep -E -i "^(.).{5}1$"






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 10 '18 at 14:01









    Kamil MaciorowskiKamil Maciorowski

    28.6k156187




    28.6k156187













    • I'm a fan of the -x flag: grep -Eix "(.).{5}1"

      – Jim L.
      Jan 30 at 22:46



















    • I'm a fan of the -x flag: grep -Eix "(.).{5}1"

      – Jim L.
      Jan 30 at 22:46

















    I'm a fan of the -x flag: grep -Eix "(.).{5}1"

    – Jim L.
    Jan 30 at 22:46





    I'm a fan of the -x flag: grep -Eix "(.).{5}1"

    – Jim L.
    Jan 30 at 22:46













    2














    If you want to use basic regular expression (without option -E), you need a backslash before the opening and closing brackets:



    grep -i '^(.).{5}1$' file


    Note that it's good idea to use single quote in your grep regex in order to avoid shell parameter expansion.






    share|improve this answer




























      2














      If you want to use basic regular expression (without option -E), you need a backslash before the opening and closing brackets:



      grep -i '^(.).{5}1$' file


      Note that it's good idea to use single quote in your grep regex in order to avoid shell parameter expansion.






      share|improve this answer


























        2












        2








        2







        If you want to use basic regular expression (without option -E), you need a backslash before the opening and closing brackets:



        grep -i '^(.).{5}1$' file


        Note that it's good idea to use single quote in your grep regex in order to avoid shell parameter expansion.






        share|improve this answer













        If you want to use basic regular expression (without option -E), you need a backslash before the opening and closing brackets:



        grep -i '^(.).{5}1$' file


        Note that it's good idea to use single quote in your grep regex in order to avoid shell parameter expansion.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 10 '18 at 14:11









        olivoliv

        31115




        31115






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • 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%2fsuperuser.com%2fquestions%2f1356890%2fusing-grep-on-txt-file-to-find-7-letter-words-that-start-with-the-same-letter%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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

            Eduardo VII do Reino Unido