0

File1 contains a series of comma separated genes:
A,B,C,D,E,F

Output required is the combinations of triplets that can be formed from the series:
ABC
BCD
CDE
DEF

The triplets are formed starting with the first three genes in the first triplet. The second triplet is formed with the second, third and fourth. The second gene of the previous triplet forms the first one of the succeeding triplet. The last triplet shall end with the last gene.

Saisha
  • 3
  • 2
  • 2
    I'm voting to close this question as off-topic because it is not a programming question – zdim May 22 '17 at 06:03
  • Your example contradicts the "The triplets are formed" description. With the latter the triplets in your example should be ABC, CDE (though that doesn't have the last triplet end with the last gene). Which is correct? – ysth May 22 '17 at 06:18
  • @ysth I just saw that and corrected it. – Saisha May 22 '17 at 06:23

2 Answers2

1
echo 'A,B,C,D,E,F,G,H,I' | awk -F, '{for(c=1;c<=NF-2;c++) print $c $(c+1) $(c+2)}'
ABC
BCD
CDE
DEF
EFG
FGH
GHI
P....
  • 17,421
  • 2
  • 32
  • 52
0

Assuming input.txt contains

a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

The following code will give the required output

lines = [i for i in open('input.txt').read().split(",")]
for i in range(len(lines)-2):
  print(''.join(lines[i:i+3]))

OUTPUT

abc
bcd
cde
def
efg
fgh
ghi
hij
ijk
...
qrs
rst
stu
tuv
uvw
vwx
wxy
xyz
jophab
  • 5,356
  • 14
  • 41
  • 60