(echo "abc*****+def";echo "def*****ghi")|awk '/abc/{match($0,"[*]+");a=substr($0,RSTART,RLENGTH);gsub("[*]","-",a);print substr($0,1,RSTART-1) a substr($0,RSTART+RLENGTH);} !/abc/{print}'