I need to do a substitution: CPF to ,C,P,F, CPM to ,C,P,M, SPF to ,S,P,F etc. I can do each of them with separate substitutions e.g. s/CPF/,C,P,F/ but I'd like to know if there is a more elegant solution. In general, how can I use the results of the search in the substitution, something like s/A.B/,A,.,B,/
assuming the pattern is the only pattern on line.
sed -e 's#\(.\)\(.\)\(.\)#,\1,\2,\3#' file
Thank you.
You can try also as,
# echo "CPF CPM SPF" | sed -e 's%\([CS]\)P\([FM]\)%,\1,P,\2%g'
,C,P,F ,C,P,M ,S,P,F
HTH.