Here is a way using (G)awk and the gensub function
awk -va="GGTGGTGGT" '
{for(i=1;i<=length(a);i++)if($0~gensub(/./,".",i,a)){print;next}}' file
Output
GGTGGTGGTAT
GGTAGTGGTAT
GGTGGTGGTAT
How it works
-va="GGTGGTGGT"
Sets the variable a to the value enclosed in the quotes(whatever you want)
{for(i=1;i<=length(a);i++)
Creates a loop from 1 to the length of the variable a.The length is the number of character inside the string.
if($0~gensub(/./,".",i,a))
I'll explain the gensub
first.
The first two args swap .
(any character) with a literal .
. The 3rd argument is the occurrence of the match from argument 1. As we are searching for a single character, then this will just move through the string replacing each character with a .
. The final arg is the string to edit and a
is used. gensub
also returns the string instead of editing the original.
$0~
Means the whole line contains whatever follows the ~
These are both contained in an if which when both evaluated will result in
$0~.GTGGTGGT
$0~G.TGGTGGT
$0~GG.GGTGGT
$0~GGT.GTGGT
$0~GGTG.TGGT
$0~GGTGG.GGT
$0~GGTGGT.GT
$0~GGTGGTG.T
$0~GGTGGTGG.
'
{print;next}
If any of those match then the line is print and all further instructions are skipped and the next line is processed.
Resources
https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html