sed to awk (regex pattern) how?

Hello,

I am trying to covert a for statement into a single awk script and I've got everything but one part.

I also need to execute an external script when "not found", how can I do that ?

for TXT in `find debugme -name "*.txt"` ;do
FPATH=`echo $TXT | sed 's/\(.*\)\/\(.*\)/\1/'`

how to add it to the following awk code?

find debugme -name "*.txt" | awk 'BEGIN{
    while( (getline line < "debug.files" ) > 0 ) {
        a[++d]=line
    }
    close("debug.files")
}
{
    filename=$0
    #FPATH=?????
    while( (getline line < filename ) > 0 ){
        f=0
        m=split(line,t," ")
        if ( t[1] ~ "(rar|r[0-9]+)" ){
            for(i=1;i<=d;i++){
                if( a ~ t[1] ){
                    print found
                    f=1
                }
            }
            if (f==0){ print not found }
        }
    }
    close(filename)
}'

sed is just doing substitution. the equivalent of substitution in awk is gsub() or sub(). read the doc on how to use it. you will also find in the doc how to execute external commands in awk. its system() or the use of getline. If you are wondering where the doc is , see here

Thanks for pointing them out, I've looked into the docs and while the system() part is easy... I still don't know to get the same results with gsub() or sub()

I'm not even sure if there's a need of using gsub() / sub()

All I need is the fullpath that find gives without the name.txt part..

So

/BLA/ABC/123.txt = /BLA/ABC

/BLA/123.txt = /BLA

and so on...

This perhaps?

    #FPATH=?????
    fpath=$0
    sub(/\/[^\/]*$/,"",fpath)

Thanks alot buddy, now I'm having another problem...

Basically befor the awk code there are some other variables in my shell script...

Example:

TEST="TESTING"

find debugme -name "*.txt" | awk 'BEGIN{.................
.........

system("echo $TEST") doesn't work...

How can I get the variables to work within the awk script? I need those informations to execute another script.. like system("exscript $TEST t[1]"....)

what you need is documented in the doc. See here. read the docs !

I've just figured it out, thanks alot guys!

system("echo ""'"$VAR1"'"" "fpath" "t[1]"")

Or somthing like that :

awk -v VAR1="$VAR1" '
. . . . 
   print VAR1,fpath t[1];
. . . .
'

Jean-Pierre.