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.

0

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .