hi,
i have file say email.temp looks like
Bell_BB 17
Bell_MONTHLY 888
SOLO_UNBEATABLE 721
and another file r3
Bell BB,Bell_BB
Bell,Bell_MONTHLY
SOLO,SOLO_UNBEATABLE
i want email.temp files $1 say Bell_BB should be replaced by r3 Bell BB and Bell_MONTHLY by Bell of r3 and so on ..
desired output of email.temp
Bell BB 17
Bell 888
SOLO 721
i tried it with sed
rk_file=$(echo "r3")
while read all; do
find=$(echo $all| awk -F"," '{print $2}' )
rep=$(echo $all| awk -F"," '{print $1}' )
echo "$find and $rep \n"
sed "s/$find/$rep/g" email.temp > email.file
done < $rk_file
but its not giving proper result only last field is SOLO is working
let me wats wrong with sed i am doing or how can i achive this using awk ?
#!/bin/bash
while read LINE
do
OLD=$( echo $LINE | cut -d, -f2 )
NEW=$( echo $LINE | cut -d, -f1 )
echo "$OLD <> $NEW"
sed -e "s/^$OLD/$NEW/" -i mail_temp
done < replacements
exit 0
#finis
[house@leonov] cat replacements
Bell BB,Bell_BB
Bell,Bell_MONTHLY
SOLO,SOLO_UNBEATABLE
[house@leonov] cat mail_temp
Bell_BB 17
Bell_MONTHLY 888
SOLO_UNBEATABLE 721
[house@leonov] bash code.bash
Bell_BB <> Bell BB
Bell_MONTHLY <> Bell
SOLO_UNBEATABLE <> SOLO
[house@leonov] cat mail_temp
Bell BB 17
Bell 888
SOLO 721
i am using ksh it is fialing with invalid option
sed: illegal option -- i
---------- Post updated at 05:44 AM ---------- Previous update was at 04:42 AM ----------
i achived it using
while read all; do
find=$(echo $all| awk -F"," '{print $2}' )
rep=$(echo $all| awk -F"," '{print $1}' )
echo "$find and $rep \n"
sed -e "s/^$find/$rep/g" email.temp | grep "$rep" | grep -v "_" >> email.file
done < r3