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

Using regular expressions for multiple hits? 4

Status
Not open for further replies.

stla

IS-IT--Management
Mar 12, 2003
190
DE
(Elementary user)

I need to use regular expressions to find certain data.

At the moment, to look for any file with a JPEG suffix i type the following: .jpg

However, I would like to look for files that are TIFF, JPEG and EPS.

Does my syntax look correct: *.jpg|*.tif|*.eps

Best regards
 
find / -name *.jpg -print
find / -name *.tiff -print
find / -name *.eps -print

these will start looking at "/" root

*.string usage here is not a regular expression

A great teacher, does not provide answers, but methods to teach others "How and where to find the answers"

bsh

35 years Bell, AT&T, Lucent, Avaya
Tier 3 for 25 years and counting
 
I would write the find as :

find . \( -name '*.jpg' -o -name '*.tif' -o -name '*.eps' \) -print

stia, are you writing your own script or is it input into a canned script or program? It will only work if it supports regular expressions (and even then, there are different types of regular expressions).

For instance, usually a '.' is any character, so if your engine supported regular expressions, it should also match

my.jpg
myjpg

and regular expressions usually want the end of the line character $, so a suffix would have to expressed '.jpg$'
to omit matches like:

my.jpgsomething
myjpgsomething
 
The Korn shell has some good pattern matching functionality...
Code:
ls -l *.@(jpg|tif|eps)
That will list everything ending in "jpg", "tif", or "eps".

The "[tt]@(<pattern>)[/tt]" construct allows logical ORs with a pipe character.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top