Passing the nawk variables to the shell

nawk '($1 ~ "1000") && ($1 ~ "5665" ) { sub ($6,"89");flag =1;print }' old.txt >> new.txt I want to set a flag in awk , if the both conditions are met. I want to pass this flag to shell Can anyone please help me on this

Hi,

Pls check if the below one helps you!

flag=`nawk '($1 ~ "1212") && ($2 ~ "1230") {flag=1; print flag}' test`

echo $flag will yield you the answer "1" after satisfying the awk conditions.

where contents of the file, "test" is as follows:

---------test-------------
1212 1230 1234 8456
1212 3434 7323 5640
--------------------------

However as far as i know, you cannot pass any awk variable to its parent shell. You need to assign it to a shell variable and then source it in your script.

Hope it helps.

rgds,

Srini