Linux – Using nawk, how to print all first names containing four characters

awklinux

Using nawk, how to print all first names containing four characters?
I tried nawk ‘/^[[:alpha:]]{4}/{print $1}’ inputfile but didn't work

Mike Harrington:(510) 548-1278:250:100:175

Christian Dobbins:(408) 538-2358:155:90:201

Susan Dalsass:(206) 654-6279:250:60:50

Jody Savage:(206) 548-1278:15:188:150

Chet Main:(510) 548-5258:50:95:135

Tom Savage:(408) 926-3456:250:168:200

Best Answer

Where someFile contains the data that you have supplied:

nawk '{if(length($1)==4){print $1}}' someFile

Output:

 Mike
 Jody
 Chet
Related Question