-2

Find people whose last name begins with S in the people.txt file (Your expression should match the entire last name, not just the initial S, and only capital S qualifies). Ensure that the first names that begin with S are not included.

the people.txt includes bellow:

Cardoza, Fred
Catto, Philipa
Duncan, Jean
Edwards, Neil
England, Elizabeth
Main, Robert
Martin, Jane
Meens, Carol
Patrick, Harry
Paul, Jeanine
Roberts, Clementine
Schmidt, Paul
Sells, Simon
Smith, Peter
Stephens, Sheila
Wales, Gareth
Zinni, Hamish

answer should be:

Schmidt, Paul
Smith, Peter

my answer currently includes:

Schmidt, Paul
Sells, Simon
Smith, Peter
Stephens, Sheila

pls elp me

Amadan
  • 191,408
  • 23
  • 240
  • 301
Luca
  • 55
  • 1
  • 7

1 Answers1

1
grep -E "^S[^,]*, [^S]" People.txt

Regex ^S[^,]*, [^S] would match to the strings which start with 'S' and 'non-S' right behind the comma.

CWLiu
  • 3,913
  • 1
  • 10
  • 14