Grep: Match a programming language

Clash 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?
shell grep
 |Â
show 5 more comments
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?
shell grep
2
Same story bro, we still need a sample file. How can anyone create better answer thansearch for " C "without any additional context?
â Iskustvo
May 9 at 15:09
2
@Iskustvo I'd go forgrep -w Cmyself, or evengrep -P 'bCb'
â roaima
May 9 at 15:11
3
Could the summary say "I'm not very good withC", and should that match? What if they list experience withK&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
 |Â
show 5 more comments
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?
shell grep
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?
shell grep
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 thansearch for " C "without any additional context?
â Iskustvo
May 9 at 15:09
2
@Iskustvo I'd go forgrep -w Cmyself, or evengrep -P 'bCb'
â roaima
May 9 at 15:11
3
Could the summary say "I'm not very good withC", and should that match? What if they list experience withK&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
 |Â
show 5 more comments
2
Same story bro, we still need a sample file. How can anyone create better answer thansearch for " C "without any additional context?
â Iskustvo
May 9 at 15:09
2
@Iskustvo I'd go forgrep -w Cmyself, or evengrep -P 'bCb'
â roaima
May 9 at 15:11
3
Could the summary say "I'm not very good withC", and should that match? What if they list experience withK&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
 |Â
show 5 more comments
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 *
add a comment |Â
up vote
0
down vote
You could use:
grep -- "<C>" your_file
This would also match I like C, because ....
add a comment |Â
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.
add a comment |Â
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 *
add a comment |Â
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 *
add a comment |Â
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 *
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 *
answered May 9 at 15:20
roaima
39.4k544105
39.4k544105
add a comment |Â
add a comment |Â
up vote
0
down vote
You could use:
grep -- "<C>" your_file
This would also match I like C, because ....
add a comment |Â
up vote
0
down vote
You could use:
grep -- "<C>" your_file
This would also match I like C, because ....
add a comment |Â
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 ....
You could use:
grep -- "<C>" your_file
This would also match I like C, because ....
answered May 9 at 15:35
chevallier
8251116
8251116
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited May 9 at 15:48
answered May 9 at 15:38
Iskustvo
667118
667118
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 Cmyself, or evengrep -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 withK&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