sed and awk question

hello,

I have this in a file

server_name=DB1
hostname=db1

I want to change hostname value to `hostname`. Any idea?

and server_name value to toUPPER (`hostname`). Any idea?

thanks

$ HN=`hostname`; awk 'BEGIN{OFS=FS="="}$1=="server_name"{$2=toupper("'"$HN"'")}; $1=="hostname" {$2="'"$HN"'"} {print}' file

//Jadu

thanks but the toupper does not seem to work:

HN=`hostname`; awk 'BEGIN{OFS=FS="="}$1=="server_name"{$2=toupper("'"$HN"'")}; $1=="hostname" {$2="'"$HN"'"} {print}' text

gives:
server_name=db2
hostname=db2

could you please advise?

With ksh ans sed:

hn="$(hostname)"
typeset -u  sn="$hn"
sed "/^server_name=/s/=.*$/=$sn/;/^hostname=/s/=.*$/=$hn/" filename > _tmp_

Then if correct mv _tmp_ to filename.

With zsh and sed:

hn=$(hostname) sn=$hn:u
sed "/^server_name=/s/=.*$/=$sn/;/^hostname=/s/=.*$/=$hn/" filename > _tmp_