assigning nawk output to shell variable

Hello friends,

I doing the follwing script , but found problem to store it to a shell variable.

#! /bin/sh

for temp in `find ./dat/vector/ -name '*.file'` 
do
   echo $temp 
   nawk -v temp=$temp 'BEGIN{  split(temp, a,"\/"); print a[4]}'
done

output:
./dat/vector/drf_all_002.file
drf_all_002.file
......
......

It shows me all the file ending with .file under ./dat/vector directory.
But I want to store the value of ( in this case ) a[4] to a shell variable fname and also the base name of the file ie, drf in this case to a separate shell variable called basename..

If any other idea with sed or with any other command most welcome..

Objective is to find all the file with extension .file and then store only the file name to a shell variable
and the base name of the file to another shell variable.

#! /bin/sh

for temp in `find ./dat/vector/ -name '*.file'` 
do
   echo $temp 
   fname = `nawk -v temp=$temp 'BEGIN{  split(temp, a,"\/"); print a[4]}' `
done

I tried with the above code but getting error..

Thanks & Regards,
User_prady

Maybe I am missing something here but why not just use the basename utility to achieve what you want instead of awk?

Dear Murphy,,

  Thanks for your reply ..

I ve no idea about the base utility you are telling about . Would you please explain me with code how to achieve my goal here..

Thanks in Advance..

fpmurphy is refering to a useful commandline tool called 'basename'
It returns everything after the last / character.
So if you call:
basename /thing/blah/stuff/filename
you get:
filename

You can use this to get just the filename out of your data

Although I heard it first time, It seems to be reli interesting ..Will try this soon.......Thanks

Cool ........Its reli Handy..

There is also dirname which does the opposite (ie returns all but the filename)

Thanks a Lot for the useful information .....

Thanking you all again..