Need help with file substitution

hello all
just trying to write a script that will read a file (line by line) and substitute (tht line) in a different file if (tht line) is present in second file

Ex: script has to read file A (line by line) and if file B has tht line it should get substituted with the line in file A

file A:

length=30

threads=40

file B:

threads=20

The script has to read file A (line by line) and has to substitute file B in this case threads=20 with threads=40. Please let me know if guys have any ideas.

NL='
'
fileB=$( cat fileB )
while read line
do
  [ -z "$line" ] && continue
  case $fileB in
    *"${line%%=*}="*)  printf "%s\n" "$line" > fileB ;;
  esac
done < fileA

Assuming the stuff behind the equals sign is what is permitted to vary,

sed -n 's/^\([^=]*=\)\(.*\)/s%\1.*%\1\2%/p' fileA | sed -f - fileB

thanks guys (cfajohnson & era) you guys are a great help...