File A has rows of genes:  A,B,C,D,E  P,Q,R  G,D,V,K  L,Q,X,I,U,G and so on.Taking each row at a time, how can one get the following type of output:  For the first row:  A,B,C  B,C,D  C,D,E For the second row:  P,Q,R  For the third row:  G,D,V  D,V,KEssentially, what I would like is to find triplets of genes from each row. The first triplet will have the first three genes. The second triplet will have the second,third,fourth genes. The last triplet will end with the last gene in the row.Achieving this manually will be a mammoth task. Since I have yet to master Linux, Perl or Python scripts to be able to write a script for this, help from this community will be appreciated!
Finding the different possible combinations
text processing;files;python;perl;bioinformatics
Using awk:function wprint() {    print w[1], w[2], w[3];}function wshift(e) {    w[1] = w[2]; w[2] = w[3]; w[3] = e;}BEGIN { FS = OFS = , }{    wshift($1);    wshift($2);    wshift($3);    wprint();    for (i = 4; i <= NF; ++i) {        wshift($i);        wprint();    }}Then:$ awk -f script data.inA,B,CB,C,DC,D,EP,Q,RG,D,VD,V,KL,Q,XQ,X,IX,I,UI,U,GThe awk script uses a three element moving window, w.  For each input row, it populates the three elements of the window with the three first fields and prints these as a comma-separated list (followed by newline). It then iterates over the remaining fields on the line, shifting them into the window and printing the window for each element.If any line in the input data contains less than two fields, you will get things likeA,,orA,B,in the output.If you are certain that every input line has at least three fields (or if you want to disregard any line that doesn't), then you may shorten the awk script slightly:function wprint() {    print w[1], w[2], w[3];}function wshift(e) {    w[1] = w[2]; w[2] = w[3]; w[3] = e;}BEGIN { FS = OFS = , }{    for (i = 1; i <= NF; ++i) {        wshift($i);        if (i >= 3) {            wprint();        }    }}A generalization of the first variation of the script with a variable window size:function wprint(i) {    for (i = 1; i < n; ++i) {        printf(%s%s, w[i], OFS);    }    print w[n]}function wshift(e,i) {    for (i = 1; i < n; ++i) {        w[i] = w[i + 1];    }    w[n] = e;}BEGIN { FS = OFS = , }{    for (i = 1; i <= n; ++i) {        wshift($i);    }    wprint();    for (i = n + 1; i <= NF; ++i) {        wshift($i);        wprint();    }}Using it:$ awk -v n=4 -f script data.inA,B,C,DB,C,D,EP,Q,R,G,D,V,KL,Q,X,IQ,X,I,UX,I,U,G