search file, change existing value based on input (awk help)

I have a file (status.file) of the form:

valueA 3450
valueB -20
valueC -340
valueD 48

I am tailing a data.file, and need to search and modify a value
in status.file...the tail is:

tail -f data.file | awk '{ print $3, ($NF - $(NF-1)) }'

which will produce lines that look like this:

valueB -40
valueD 220
valueA -100

so I think what I would like to do is add a pipe to the tail command,
and send those lines to an awk command/program. It should then
search through status.file, and add the value to the correct line.

For example, using the above status.file, a line of data (after having
gone through the tail line) of
valueC -30

would result in status.file being changed to:

valueA 3450
valueB -20
valueC -370
valueD 48

Any help/tips would be greatly appreciated, thanks

tail -f data.file | awk ' 
BEGIN { 
      while ( getline < "status.file" )  { arr[$1]=$2 } 
}
{      if ( arr[ $3 ] != "" ) { arr[$3] = arr[$3] + $NF - $(NF-1)  }    }
END { 
       for( key in arr ) print key,arr[key] 
}'

Hi,

Thanks for responding, I appreciate it.

It looks like this does what I want, except it doesn't save the new results in status.file. I've saved the code above (from "BEGIN" to "key]}") into adjust_results.awk, and when I do this:

tail data.file | awk -f adjust_results.awk

the output is correct...but the change hasn't been saved in status.file.

you are trying to save output to replace the existing status.file?

tail data.file | awk -f adjust_results.awk > status.sfile

redirect the output to status.file

(not sure if that's what you're looking for ? ) =)