Execution Problems with scan and change file data content

Input file

>Read_1
XXXXXXXXXXSDFXXXXXDS
ASDRXXXXXTGAGTXXXXXT
TGTGATXXXXXAXXXXGXXA
.
.

Desired output file

>Read_1
XXXXXXXXXXXXXXXXXXDS
ASDRXXXXXTGAGTXXXXXT
TGTGATXXXXXXXXXXXXXA
.
.


Once I scan the last "X" and next coming "X" 's distance is less than or equal to 3 letters, I will replace those letter between the last "X" and next coming "X" with "X"
Thanks for any advice.

 perl -pe 's/X[^X]X/XXX/g;s/X[^X]{2}X/XXXX/g;s/X[^X]{3}X/XXXXX/g;' input
1 Like

sed 's/X[^X]X/XXX/g;s/X[^X][^X]X/XXXX/g;s/X[^X][^X][^X]X/XXXXX/g' input >output

1 Like

Hi bartus11,
Thanks for your perl command.
Do you have any idea if my input data is shown as below:

>Read_1
XXXXXXXXXXSDFXXXXXDS  (condition 1: After the last "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X")
TREXXXXXXXSDFXXXXXDS (condition 2: Before the first "X" per line, if the distance is less than or equal to 3 letter, replace those not "X" letter with "X")
.
.

Desired output:

>Read_1
XXXXXXXXXXSDFXXXXXDS
XXXXXXXXXXSDFXXXXXDS
.
.

Do you have any suggestion if facing the above situation?
I got try using this one for condition 1. But it is not worked:

perl -pe 's/X[^X]{2}$/XXX/g' input

Thanks for any advice.

sed 's/X[^X][^X][^X]$/XXXX/;s/X[^X][^X]$/XXX/;s/X[^X]$/XX/;s/^[^X][^X][^X]X/XXXX/;s/^[^X][^X]X/XXX/;s/^[^X]X/XX/' input > output
while(<DATA>){
  s/(?<=X)([^X]+)(?=X)/(length($1)>3)?$1:"-" x length($1)/eg;
  print;
}
__DATA__
XXXXXXXXXXSDFXXXXXDS
XXaaXbbXXXXXXXSDFXXXXXDS
ASDRXXXXXTGAGTXXXXXT
TGTGATXXXXXAXXXXGXXA