1

So I have a file list with list of the people in a company. Each line contains Position(a short string), years, name(first and last), salary and nationality(three capital letters). They are divided with commas.

I want to find two things using grep and regex:

  1. All people whose last name starts with C.
  2. All people who have 3 names

For the first I have tried: grep -E 'C\>' list, but it gives back only one name(strange). For the second: grep "[[:alpha:]]\b[ ]\?[[:alpha:]]\b[]\?[[:alpha:]]" list, but it also fails.

2

\> is the (zero length) regexp for the end of the word so C\> will probably not match last names that start with a 'C'. Maybe you should try \<C instead.

[[:alpha:]] matches exactly one character so this is also very unlikely to match a real name. You should append a multiplier like * or + (only in ERE?).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.