4 added 204 characters in body
source | link

Short awk solution:

awk '{ printf "%06d.%d\t%s\n",(!a[$1]++? ++c:c),a[$1],$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c - c is a prefix value incremented for each unique entry (before decimal point)

  • a[$1] - suffix value (after decimal point) - points to the number of occurrences of the 1st field value $1

  • %06d.%d - output format specificator, where %06d points to the size of the integer part of the number d (size 6 with leading zeros 06) and .%d - the scale of the number (fractional part)


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3

Short awk solution:

awk '{ printf "%06d.%d\t%s\n",(!a[$1]++? ++c:c),a[$1],$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c - c is a prefix value incremented for each unique entry (before decimal point)

  • a[$1] - suffix value (after decimal point) - points to the number of occurrences of the 1st field value $1


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3

Short awk solution:

awk '{ printf "%06d.%d\t%s\n",(!a[$1]++? ++c:c),a[$1],$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c - c is a prefix value incremented for each unique entry (before decimal point)

  • a[$1] - suffix value (after decimal point) - points to the number of occurrences of the 1st field value $1

  • %06d.%d - output format specificator, where %06d points to the size of the integer part of the number d (size 6 with leading zeros 06) and .%d - the scale of the number (fractional part)


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
3 optimized solution
source | link

Short awk solution:

awk '{ if (!a[$1]++){ ++c; suf=1 } else suf++; printf "%06d.%d\t%s\n",(!a[$1]++? ++c:c),sufa[$1],$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c; suf=1++c - c is a prefix value incremented for each unique entry (before decimal point),  

  • sufa[$1] is a - suffix value (after decimal point)

  • else suf++ - increment suffixpoints to the number of occurrences of the 1st field value only for duplicate entries$1


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3

Short awk solution:

awk '{ if (!a[$1]++){ ++c; suf=1 } else suf++; printf "%06d.%d\t%s\n",c,suf,$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c; suf=1 - c is a prefix value (before decimal point), suf is a suffix value (after decimal point)

  • else suf++ - increment suffix value only for duplicate entries


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3

Short awk solution:

awk '{ printf "%06d.%d\t%s\n",(!a[$1]++? ++c:c),a[$1],$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c - c is a prefix value incremented for each unique entry (before decimal point) 

  • a[$1] - suffix value (after decimal point) - points to the number of occurrences of the 1st field value $1


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
2 added explanantion
source | link

Short awk solution:

awk '{ if (!a[$1]++){ ++c; suf=1 } else suf++; printf "%06d.%d\t%s\n",c,suf,$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c; suf=1 - c is a prefix value (before decimal point), suf is a suffix value (after decimal point)

  • else suf++ - increment suffix value only for duplicate entries


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3

Short awk solution:

awk '{ if (!a[$1]++){ ++c; suf=1 } else suf++; printf "%06d.%d\t%s\n",c,suf,$0 }' file

The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3

Short awk solution:

awk '{ if (!a[$1]++){ ++c; suf=1 } else suf++; printf "%06d.%d\t%s\n",c,suf,$0 }' file
  • !a[$1]++ - check for unique value of the 1st field $1(used as index for the array a)

  • ++c; suf=1 - c is a prefix value (before decimal point), suf is a suffix value (after decimal point)

  • else suf++ - increment suffix value only for duplicate entries


The output:

000001.1    Ca3CNSNP431180  2428    2435    0   TTTATttt    AT-Hook 1
000002.1    Ca3CNSNP431179  2429    2437    0   TTATTttat   AT-Hook 1
000003.1    Ca3CNSNP431178  2428    2436    0   TTTATttta   AT-Hook 1
000004.1    Ca4CNSNP431177  1384    1388    0   ATTGA   NF-YB;NF-YA;NF-YC   1
000005.1    Ca4CNSNP431176  1382    1386    0   AGATT   Myb/SANT;MYB;ARR-B  1
000006.1    Ca4CNSNP431175  1382    1386    0   AGATT   GATA;tify   1
000007.1    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000007.2    Ca4CNSNP431174  1386    1398    0   tgaAATTTtcatt   TCR;CPP 2
000008.1    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000008.2    Ca4CNSNP431172  1383    1395    0   gattgAAATTttc   TCR;CPP 2
000009.1    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.2    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
000009.3    Ca3CNSNP430205  3334    3343    0   tATATAtata  AT-Hook 3
1
source | link