copying one field to another

Hi,

I am trying to copy one field to another only on lines that match a certain string. Here is what i have tried:

awk '/nch/' {gsub($3,$5,$0)}' file

I need to copy $5 (field) to $3 if the line contains "nch"
I have never used gsub and am not sure if this is the right way.

file:
----------------------------------------
mod pad1 pad2 pad3 pad4 col row etc
nch pad4 pad5 pad6 pad7 col1 row1 time
nch pad2 pad3 pad5 pad8 col row date
----------------------------------------

Thanks for any suggestions.

Since you are only doing one substitution, you don't need gsub(); sub() will do:

awk '/nch/ {sub($3,$5,$0)}{print}' file

Or, more accurately:

awk '/nch/ { $3 = $5 } {print}' file

Thanks it works!