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?
Replacing all the occurrence of the pattern in a line : The substitute flag /g (global replacement) specifies the sed command to replace all the occurrences of the string in the line.
How SED Works. In the syntax, you only need to provide a suitable “new string” name that you want to be placed with the “old string”. Of course, the old string name needs to be entered as well. Then, provide the file name in the place of “file_name” from where the old string will be found and replaced.
If using a sed script, "i\" immediately followed by a literal newline will work on all versions of sed. Furthermore, the command "s/$/This line is new/" will only work if the hold space is already empty (which it is by default).
this is how you do it with sed
$ echo "test ATCG GATC test" | sed 'y/ATCG/TAGC/'
test TAGC CTAG test
use tr.
cat file | tr ATCG TAGC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With