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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using * as a wildcard 1

Status
Not open for further replies.

noiz

IS-IT--Management
Apr 19, 2001
17
US
hi

I'm using the bourne shell in BSD 4.2 and i'm getting wierd results when i use a wildcard in a simple awk script i'm running.

when i run:
awk '/d*/ {print $0 }' tmp2 it matches every line i have in that file even those that don't start with "d"

when i run: awk '/dr*/ { print $0 }' tmp2 i get
drwxr-xr-x 3 zion users 512 May 21 02:34 .
drwxr-xr-x 3 zion users 512 May 1 11:09 ..
drwxr-xr-x 2 zion users 512 May 18 14:08 t1
-rw-r--r-- 1 zion users 273 May 18 18:17 tweedle
-rw-r--r-- 1 zion users 49 Mar 28 22:49 wordlist

but when i run:
awk '/drw*/ { print $0 }' tmp2 i get a list of only directories? any one know why it is doing this?

tks

zion
<><
=-)
 

Hi, zion!

A bit of theory: asterisk * matches any number (or none) of the single character that immediately precedes it. So, /d*/ matches all lines in tmp2, because letter d is in any line.

You can get a list of only directories with this regular expression: /^d.*/. That means:
every line that has letter d at the beginning of the line. Metacharacter ^ matches the following regular expression at the beginning of the line.

God bless you!

KP.


God
 
Hello, zion!

I found good site about regular expressions:


Excellent book for regular expressions is &quot;Mastering Regular Expressions,&quot; by Jeffrey E. F. Friedl; you can see this site:


There is 4th chapter from Mr. Friedl's book on this site:


You can also try &quot;Regular-expression inspector:&quot;


Here you can find quick metacharacter reference.

RegExp is very powerful tool. I use it with awk for searching the Bible in ASCII format and for data analysis.

Bye!

KP.
 
Krunek,

Thanks, i'll check out those sites.

God bless,

zion
<><
=-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top