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!

Glob Pattern Matching

Status
Not open for further replies.

fdservices

IS-IT--Management
Mar 10, 2005
52
FR
Here's what I want to do:

set $prefix "ABC"
set $directory "/home/user"
set files [lsort -dictionary [glob -directory "$directory" -tails -type f "${prefix}[0-9]+-*.pdf"]]}]

where

"${prefix}[0-9]+-*.pdf" is "ABC" + any sequence of numeric characters + "-" + any sequence of characters + ".pdf"

needless to say I can't make it work. Can anyone help me?

Andrew
 
Hi

fdservices said:
any sequence of numeric characters
No way. [tt]glob[/tt]'s parameter is a pattern, not a regular expression, patters are not suitable to describe so complex things.

I would use a less restrictive pattern, then [tt]lsearch[/tt] the results using a regular expression to filter out the unwanted ones. Of course, after correcting the pattern syntax ( [tt][[/tt]..[tt]][/tt] is used for command substitution in Tcl, so you have to escape them in the pattern ) :
Code:
[b]set[/b] files [teal][[/teal][b]lsort[/b] [teal]-[/teal]dictionary [teal][[/teal][b]lsearch[/b] [teal]-[/teal][b]regexp[/b] [teal]-[/teal]all [teal]-[/teal]inline [teal][[/teal][b]glob[/b] [teal]-[/teal]directory [green][i]"$directory"[/i][/green] [teal]-[/teal]tails [teal]-[/teal]type f [green][i]"${prefix}?*-*.pdf"[/i][/green][teal]][/teal] [green][i]"^${prefix}[/i][/green][COLOR=red yellow]\[/color][lime][i][[/i][/lime][green][i]0-9[/i][/green][COLOR=red yellow]\[/color][lime][i]][/i][/lime][green][i]+-.*[/i][/green][lime][i]\.[/i][/lime][green][i]pdf$"[/i][/green][teal]]][/teal][teal]}[/teal][teal]][/teal]
[small][maroon]Warning[/maroon] The above code was tested only partially[/small]

Feherke.
 
That's the ticket

Thanks for the help

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top