I need to replace three specific characters (triplets) in the text. I want to combine a pattern starting at positions 1, 4, 7, 10, 13, etc., but not at positions 2, 3, 5, 6, etc.
For example, I want to look / replace taaon NNNin the text ctaagctaaggcgtaaga, and I want to get ctaagcNNNggcgtaaga.
The first occurrence of "taa" begins at position 2 and should not be matched / replaced, the second occurrence begins at position 7 and is replaced, the third occurrence begins at position 14 and is not matched.
My solution so far is to separate the triplets from the “+”, perform a replacement, and remove all the “+”. However, I am thinking of a more elegant solution with the sed command.
echo $dna | sed 's/.../&+/g;s/+$//' | sed 's/taa/NNN/g' | sed 's/+//g'
source
share