I need to invert a DNA text string by changing all the A's to T's, T's to A's, C->G, and G->C.
Can I elegantly handle this in sed (or other command line) without a whole chain of sed global replace commands?
I need to invert a DNA text string by changing all the A's to T's, T's to A's, C->G, and G->C.
Can I elegantly handle this in sed (or other command line) without a whole chain of sed global replace commands?
use tr. It will be far superior to sed for this job.
cat file | tr ATCG TAGC
edit: Just to clarify why sed is bad at this, you will have a tricky time getting it not to reverse the changes you have made on a prior pass, e.g. on one pass you turn A to T but then on a pass where you want to turn T to A, how do you get sed to ignore the Ts that were originally As? It can maybe be done but I can't think of a nice way. tr does this kind of thing naturally, so long as your mapping is a single char to a single char.
this is how you do it with sed
$ echo "test ATCG GATC test" | sed 'y/ATCG/TAGC/'
test TAGC CTAG test