Re: regexp

From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 10/31/03


Date: Fri, 31 Oct 2003 19:46:40 +0100

2003/10/31, 10:46(-06), Kumar Sundaram:
> How do a get a regexp to match the data given below in a find statement. I
> use a * at the end and it maches a number or nothing.
>
> for script in `find /home/xxx -name "send[a-d][a-z][a-z]*" -print`
> do
> echo "$script"
> nohup $script &
> echo "$script executed"
> done

I'm not sure to understand your question. Does this somehow
answer your question:

find /home/xxx -type f -perm -111 \( \
  -name 'send[a-d][a-z][a-z]' -o \
  -name 'send[a-d][a-z][a-z][0-9]' \) -exec sh -c '
    printf %s\\n "$1"
    nohup "$1" &
    printf "%s started in background\n" "$1"' {} {} \;

-name argument is not a regexp but a wildcard, see man fnmatch
for how to use wildcards.

-perm 111
is a check to see if the file is executable. Note that it just
checks wether everyone has execute permission for it. That's an
approximation. Better solution could be:

find /home/xxx -type f -perm +111 \( \
    -name 'send[a-d][a-z][a-z]' -o \
    -name 'send[a-d][a-z][a-z][0-9]' \) -exec sh -c '
      [ -x "$1" ] || exit 1
      printf %s\\n "$1"
      nohup "$1" &
      printf "%s started in background\n" "$1"' {} {} \;

Unfortunately, find has not option to check if *you* (the user
running find) have the right to execute a given file.

-- 
Stéphane                      ["Stephane.Chazelas" at "free.fr"]


Relevant Pages

  • Re: regexp
    ... > the regexp function that I don't understand. ... result of the command is substituted into the if command as ... evaluated to determine whether to execute the body. ... Tcl syntax is ...
    (comp.lang.tcl)
  • Re: Great SWT Program
    ... up regexps in the middle of a discussion of wildcard searches. ... Probably because it was a regexp expression that was posted. ... wildcard expressions by sight. ... "ab*c" is both a valid wildcard expression and a valid regexp ...
    (comp.lang.java.programmer)
  • Re: Outlook CSV Parser
    ... it might execute a little faster. ... Thank you for pointing out .. ... it failed to seperate the records in the right fashion. ... I am sure If we modify that regexp a little ...
    (perl.beginners)
  • ignoring a wildcard statement
    ... We are trying to execute and if then part of our script against a ... the script to map a drive based on the first couple of letters in the ... The computer EXTRA1 is not reading the wildcard. ...
    (microsoft.public.scripting.vbscript)
  • Re: Memory exhausted: error when match() function is called with two different regexp
    ... I have the following small snippet of awk code ... When I execute the above small snippet of code with a big file as ... function test{regexp=foo; match} ...
    (comp.lang.awk)