Using grep and cut within awk

Hi

My input file looks like as follows: say a.txt

"aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd"
"aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd"
"aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd"
"aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd"
"aaaa cc","224 AW","ss cccccc","P06 09/10","dddddd"

There is another file b.txt which acts like lookup of "AW" in a.txt, like

1 AW
2 AS
.....

My output should be like:

aaaa      2242009W1000001(last 5 characters -> 00001 is look up value for AW from b.txt).

Am able to achieve till "aaaa 2242009W10" using the following command

sed -e 's/ /,/g' -e 's/\//,/g' -e 's/"//g' a.txt|awk -F"," '{printf "%-10s%3s%s%s%s%s\n",$1,$3,"20",$8,"W",$9}'

Kindly help in getting the "grep AW b.txt| cut -d" " -f1" part in awk command itself, so that seperate script can be avoided.

Thanks in Advance.

Try and adapt the following awk script :

awk -F '[[:space:],/]' '
NR==FNR { lookup[$2] = $1 ; next }
{
   gsub(/"/,"");
   printf "%-10s%3s20%sW%s%05d\n",$1,$3,$8,$9,lookup[$4];
}
' b.txt a.txt

jean-Pierre.

sed -e 's|"||g;s|[ /]|,|g' b.txt a.txt |awk -F, '!$3{A[$2]=$1;next}{printf "%-10s%s20%sW%s%05d\n",$1,$3,$8,$9,A[$4]}'

Both the commands work perfectly.. Can u guys please explain
"!$3{A[$2]=$1;next}" part of the command.. Thanx a lot for ur help

Sure:
If $3 does not exist (in other words: if the input originates from b.txt) then set the array A with key $2 to the value of $1. next means skip the next commands and re-enter the loop. The rest of the code gets executed when $3 contains a value, i.e. when the input originates from a.txt.

Thanks Scrutinizer....Understood much better now..