Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk metacharacters: newbie wow I didn't know there was an awk forum 1

Status
Not open for further replies.

goldenradium2001

Technical User
Mar 22, 2002
91
US
Here's my question that I posted in the UNIX Scripting forum before I discovered there was a wonderful awk forum. I'm dealing with three metacharacters...+, *, and ?. Here's my file:
Jeen
Jeff
Jessica
Jerry
John
Jo
Josh
Here's my awk statements:

nawk '/Je+/' file

nawk '/Je*/' file

nawk '/Je?/' file

For the first statement it only retrieves:
Jeen
Jeff
Jessica
Jerry

For the second statement, it retrieves all records.

For the third statement, it retrieves all records.

Is there something wrong in my syntax? Or is this a bad example to show the differences between the +, ?, and * metacharacters? Help?? Can anyone give me a better clearer example of how these metacharacters would work?

Thanks!
 
x* matches ZERO or more consecutive substrings x
x+ matches ONE or more consecutive substrings x
x? matches the NULL string or any strings matched by x

ab?c matches ac and abc
jm
 
So if you have

jn
jen
jeen
jeeen

je*n matches them all
je+n matches all except jn
je?n matches jn and jen CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top