Grep: Match a programming language

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 directory with many files. The files contain summaries of people that describe their experience using a programming language.



The problem comes when i want to match a programming language that has only one letter like C.



For the others i have no problem.



grep C++
grep Ada
grep Pascal
grep Scheme


How can i make a grep to match C and not confuse it with other words presented in the files?







share|improve this question















  • 2




    Same story bro, we still need a sample file. How can anyone create better answer than search for " C " without any additional context?
    – Iskustvo
    May 9 at 15:09







  • 2




    @Iskustvo I'd go for grep -w C myself, or even grep -P 'bCb'
    – roaima
    May 9 at 15:11






  • 3




    Could the summary say "I'm not very good with C", and should that match? What if they list experience with K&RC ? We need to see a good example of the input.
    – Jeff Schaller
    May 9 at 15:12










  • @roaima Judging from the other question he posted, I would say he is familiar with both of those methods and probably needs something more complex.
    – Iskustvo
    May 9 at 15:13










  • @Iskustvo i don't need complex format.
    – Andres ZW
    May 9 at 15:16














up vote
0
down vote

favorite












I have a directory with many files. The files contain summaries of people that describe their experience using a programming language.



The problem comes when i want to match a programming language that has only one letter like C.



For the others i have no problem.



grep C++
grep Ada
grep Pascal
grep Scheme


How can i make a grep to match C and not confuse it with other words presented in the files?







share|improve this question















  • 2




    Same story bro, we still need a sample file. How can anyone create better answer than search for " C " without any additional context?
    – Iskustvo
    May 9 at 15:09







  • 2




    @Iskustvo I'd go for grep -w C myself, or even grep -P 'bCb'
    – roaima
    May 9 at 15:11






  • 3




    Could the summary say "I'm not very good with C", and should that match? What if they list experience with K&RC ? We need to see a good example of the input.
    – Jeff Schaller
    May 9 at 15:12










  • @roaima Judging from the other question he posted, I would say he is familiar with both of those methods and probably needs something more complex.
    – Iskustvo
    May 9 at 15:13










  • @Iskustvo i don't need complex format.
    – Andres ZW
    May 9 at 15:16












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a directory with many files. The files contain summaries of people that describe their experience using a programming language.



The problem comes when i want to match a programming language that has only one letter like C.



For the others i have no problem.



grep C++
grep Ada
grep Pascal
grep Scheme


How can i make a grep to match C and not confuse it with other words presented in the files?







share|improve this question











I have a directory with many files. The files contain summaries of people that describe their experience using a programming language.



The problem comes when i want to match a programming language that has only one letter like C.



For the others i have no problem.



grep C++
grep Ada
grep Pascal
grep Scheme


How can i make a grep to match C and not confuse it with other words presented in the files?









share|improve this question










share|improve this question




share|improve this question









asked May 9 at 15:05









Andres ZW

84




84







  • 2




    Same story bro, we still need a sample file. How can anyone create better answer than search for " C " without any additional context?
    – Iskustvo
    May 9 at 15:09







  • 2




    @Iskustvo I'd go for grep -w C myself, or even grep -P 'bCb'
    – roaima
    May 9 at 15:11






  • 3




    Could the summary say "I'm not very good with C", and should that match? What if they list experience with K&RC ? We need to see a good example of the input.
    – Jeff Schaller
    May 9 at 15:12










  • @roaima Judging from the other question he posted, I would say he is familiar with both of those methods and probably needs something more complex.
    – Iskustvo
    May 9 at 15:13










  • @Iskustvo i don't need complex format.
    – Andres ZW
    May 9 at 15:16












  • 2




    Same story bro, we still need a sample file. How can anyone create better answer than search for " C " without any additional context?
    – Iskustvo
    May 9 at 15:09







  • 2




    @Iskustvo I'd go for grep -w C myself, or even grep -P 'bCb'
    – roaima
    May 9 at 15:11






  • 3




    Could the summary say "I'm not very good with C", and should that match? What if they list experience with K&RC ? We need to see a good example of the input.
    – Jeff Schaller
    May 9 at 15:12










  • @roaima Judging from the other question he posted, I would say he is familiar with both of those methods and probably needs something more complex.
    – Iskustvo
    May 9 at 15:13










  • @Iskustvo i don't need complex format.
    – Andres ZW
    May 9 at 15:16







2




2




Same story bro, we still need a sample file. How can anyone create better answer than search for " C " without any additional context?
– Iskustvo
May 9 at 15:09





Same story bro, we still need a sample file. How can anyone create better answer than search for " C " without any additional context?
– Iskustvo
May 9 at 15:09





2




2




@Iskustvo I'd go for grep -w C myself, or even grep -P 'bCb'
– roaima
May 9 at 15:11




@Iskustvo I'd go for grep -w C myself, or even grep -P 'bCb'
– roaima
May 9 at 15:11




3




3




Could the summary say "I'm not very good with C", and should that match? What if they list experience with K&RC ? We need to see a good example of the input.
– Jeff Schaller
May 9 at 15:12




Could the summary say "I'm not very good with C", and should that match? What if they list experience with K&RC ? We need to see a good example of the input.
– Jeff Schaller
May 9 at 15:12












@roaima Judging from the other question he posted, I would say he is familiar with both of those methods and probably needs something more complex.
– Iskustvo
May 9 at 15:13




@roaima Judging from the other question he posted, I would say he is familiar with both of those methods and probably needs something more complex.
– Iskustvo
May 9 at 15:13












@Iskustvo i don't need complex format.
– Andres ZW
May 9 at 15:16




@Iskustvo i don't need complex format.
– Andres ZW
May 9 at 15:16










3 Answers
3






active

oldest

votes

















up vote
1
down vote













If all you want to do is to match the single letter C then you should be able to do this with grep easily enough. Add the -i flag for case-insensitive matching.



grep -w C *





share|improve this answer




























    up vote
    0
    down vote













    You could use:



    grep -- "<C>" your_file


    This would also match I like C, because ....






    share|improve this answer




























      up vote
      0
      down vote













      In general your solution should be grep -w C or grep -P 'bCb', like roaima suggested.



      To ignore special cases like C++, you can always use negative look-ahead:



      grep -P "bCb(?!+)" file


      (?!+) makes grep ignore the match if the first following character after C is a +.

      If there are more specific cases, you can just edit this part of code to match them also.






      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%2f442802%2fgrep-match-a-programming-language%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote













        If all you want to do is to match the single letter C then you should be able to do this with grep easily enough. Add the -i flag for case-insensitive matching.



        grep -w C *





        share|improve this answer

























          up vote
          1
          down vote













          If all you want to do is to match the single letter C then you should be able to do this with grep easily enough. Add the -i flag for case-insensitive matching.



          grep -w C *





          share|improve this answer























            up vote
            1
            down vote










            up vote
            1
            down vote









            If all you want to do is to match the single letter C then you should be able to do this with grep easily enough. Add the -i flag for case-insensitive matching.



            grep -w C *





            share|improve this answer













            If all you want to do is to match the single letter C then you should be able to do this with grep easily enough. Add the -i flag for case-insensitive matching.



            grep -w C *






            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered May 9 at 15:20









            roaima

            39.4k544105




            39.4k544105






















                up vote
                0
                down vote













                You could use:



                grep -- "<C>" your_file


                This would also match I like C, because ....






                share|improve this answer

























                  up vote
                  0
                  down vote













                  You could use:



                  grep -- "<C>" your_file


                  This would also match I like C, because ....






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    You could use:



                    grep -- "<C>" your_file


                    This would also match I like C, because ....






                    share|improve this answer













                    You could use:



                    grep -- "<C>" your_file


                    This would also match I like C, because ....







                    share|improve this answer













                    share|improve this answer



                    share|improve this answer











                    answered May 9 at 15:35









                    chevallier

                    8251116




                    8251116




















                        up vote
                        0
                        down vote













                        In general your solution should be grep -w C or grep -P 'bCb', like roaima suggested.



                        To ignore special cases like C++, you can always use negative look-ahead:



                        grep -P "bCb(?!+)" file


                        (?!+) makes grep ignore the match if the first following character after C is a +.

                        If there are more specific cases, you can just edit this part of code to match them also.






                        share|improve this answer



























                          up vote
                          0
                          down vote













                          In general your solution should be grep -w C or grep -P 'bCb', like roaima suggested.



                          To ignore special cases like C++, you can always use negative look-ahead:



                          grep -P "bCb(?!+)" file


                          (?!+) makes grep ignore the match if the first following character after C is a +.

                          If there are more specific cases, you can just edit this part of code to match them also.






                          share|improve this answer

























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            In general your solution should be grep -w C or grep -P 'bCb', like roaima suggested.



                            To ignore special cases like C++, you can always use negative look-ahead:



                            grep -P "bCb(?!+)" file


                            (?!+) makes grep ignore the match if the first following character after C is a +.

                            If there are more specific cases, you can just edit this part of code to match them also.






                            share|improve this answer















                            In general your solution should be grep -w C or grep -P 'bCb', like roaima suggested.



                            To ignore special cases like C++, you can always use negative look-ahead:



                            grep -P "bCb(?!+)" file


                            (?!+) makes grep ignore the match if the first following character after C is a +.

                            If there are more specific cases, you can just edit this part of code to match them also.







                            share|improve this answer















                            share|improve this answer



                            share|improve this answer








                            edited May 9 at 15:48


























                            answered May 9 at 15:38









                            Iskustvo

                            667118




                            667118






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442802%2fgrep-match-a-programming-language%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                Peggy Mitchell

                                Palaiologos

                                The Forum (Inglewood, California)