Question about a awk command

Hi,

I am studying an awk command:

awk '{ sub(/\/\/.*/, "", $NF); print }' input.txt

The input.txt is:

char*s1="//hello"; //comment
//delete
/* hello //*/

The output is :

char*s1="//hello";

/* hello

My question is why the contents ("//hello") is not deleted? And what does $NF mean?

Thanks

$NF represents the last field in a record (line), so the sub is removing //.* from the last field.

//Hello"; is not deleted because it's not in the last field.

I would recommend reading AWK manual.

Refer section: Variables and Special Variables