question about using grep
hello and thank you in advance for your help. I'm trying to create a grep command for a study exercise that requires me to create a grep command that will match names within a file that and with a vowel, but start with consonants. so far i came up with this: $grep '^[A-Z][AEIOU' ./filename
I do get an output but is not what I'm looking for. I would really appreciate your help. |
Welcome. You'll need to review the manual page for grep and turn your attention to the -E or -P options.
Code:
man grep Then review your first bracket expression since you ask for a consonant but include all the letters. |
Quote:
|
The pattern should be basic enough not to require options -E and -P, but you can indeed if you want to avoid some escapings ;)
However option -i could be useful. By the way, "Y" is a (semi-)vowel as well so don't forget it. Anf finally pay attention to quantifiers, especially "+" (see "Repetition" section of grep man page). |
The most easy approach is probably to first grep for everything that ends with a vowel [aeiou]$ and then grep in a pipe for everything of that that doesn't (--invert-match) start with a vowel ^[aeiou]. Like already mentioned case-insensitive -i might be needed too.
Assuming you don't have to only present the result, but will also have to explain it. To put it different: i would solve one of the both problems at a time. If that is sorted, you should easily be able to make it more sexy. |
being this sounding like a standard teacher question to the students, so it's most likely to have been asked before, so I googled it,
Code:
grep -oiw '[bcdfghjklmnpqrstvwxyz][a-z]*[aeiou]' source: https://unix.stackexchange.com/quest...end-in-a-vowel a quick test, and it looks like it works. Code:
$ ls /media/ntfs1 | grep -oiw '[bcdfghjklmnpqrstvwxyz][a-z]*[aeiou]' |
Thank you, everyone!!!
I had come up with this: grep '^[^aeiou][a-z]*[aeiou]*' ./myfile.txt but BW-userx command seems to be more specific but I think there's a carat missing and a dollar sign at the end, so this is what I did instead: grep -oiw '^[bcdfghjklmnpqrstvwxyz][a-z]*[aeiou]$' and it worked. thank you yall are awesome!!!! |
Quote:
|
Quote:
Code:
grep -oiw '[bcdfghjklmnpqrstvwxyz][a-z]*[aeiou]' By the way, please put your code/commands inside [CODE] tags. Quote:
|
probably you want to check character classes like [:alpha:] and similar.
https://www.gnu.org/software/grep/ma...pressions.html |
great link
Quote:
|
All times are GMT -5. The time now is 07:39 AM. |