perform actions at specific locations in data frame

Hi everyone,

I got a data frame like the one below and and would like to do the following:

Ignore the first 3 rows and check in all following rows the second position. If the value is >500, subtract 100.

Example DF:

ABC    22    DE    12    
BCD    223    GH    12
EFG    2104    DH    25
ghF    3452    TH    35
sft    512    as    10

How it should look like:

ABC    22    DE    12    
BCD    223    GH    12
EFG    2104    DH    25
ghF    3352    TH    35
sft    112    as    10

Any idea how this could be done with sed/awk?

many thanks for your help!

Try:

awk 'NR>3 && $2 > 500{$2-=100}1' file
1 Like

Thanks a lot - exactly what I was looking for:-)

---------- Post updated at 05:22 PM ---------- Previous update was at 04:28 PM ----------

sorry, I just realized that like this the columns are now space separated (should stay tab-delimited). How could this be done?

many thanks again

awk 'NR>3 && $2>500{$2-=100}1' OFS="\t" file
1 Like

thanks!