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!

Regexp problem

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I would like to test a file and determine whether it is a Cshell, awk or other type of script. Scripts will often start with something like #!/bin/sh or #!/bin/nawk..

I did the following
set fd [open $file "r"]
gets $fd line
if [regexp {#!\/bin\/*awk} $line]
{
it's an awk or nawk or gnawk script
}
else

...

This does not seem to work. Does someone has some examples with regexp?

Thanks!
 
One change you need to make in this example: add a "." before your "*". In your example, the "*" quantifier (0 or more), applied to the previous character, a "/". I'm assuming that you really wanted ".*" (0 or more of any character).

Also, you don't really need to escape your "/" characters, as they don't have special meaning to the regular expression parser. Which gives us:

[tt]regexp {#!/bin/.*awk} $line[/tt] - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks a lot it worked fine!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top