Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

\> 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?).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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