<p>Using sed:</p>

<pre><code>sed 's,\([01][/|][01]\):[^ ]*,\1,g' file
#    ^  ^               ^     ^  ^   
#    |  |               |     |  *--- applies to all found pattern
#    |  |               |     *------ print the content inside the parenthesis
#    |  |               *------------ any character except a space
#    |  *---------------------------- the pattern to be kept
#    *------------------------------- substitution
</code></pre>

<p>You also may want to format the output using <code>column</code> command:</p>

<pre><code>sed 's,\([01][/|][01]\):[^ ]*,\1,g' file | column -t
#CHROM  POS     ID  REF   ALT   FATHER  MOTHER  DAUGHTER1  DAUGHTER2  DAUGHTER3   SON1  SON2
1       736689  .   T     A     0/0     1/0     0|0        0|1        0|1        0|0   0|1
1       758663  .   CGCC  TTAG  0/0     0/1     0|0        0|1        0|1        0|0   0|1
</code></pre>

<p>Note the comma separators in the sed command can replaced with other characters typically "/"</p>

CC BY-SA 4.0
2019-09-30T06:24:33.317Z
2019-09-30T11:15:36.173Z
2019-09-30T11:15:36.173Z
oliv
<p>Is it possible to filter out all the characters that come after the genotype, for example, I have a data </p>

<pre><code>#CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
1 736689 . T A 0/0:37:1.224:2.367:0.054:0.0:108:0.00:4.75:0.53:0.00:T,37,2.367:37,0 1/0:33:1.099:3.320:0.091:358.5:359:0.59:4.34:0.59:0.08:A,15,1.149,T,18,2.171:18,15 0|0:30:0.999:1.314:0.033:0.0:87:0.00:1.16:0.00:0.00:T,30,1.314:30,0 0|1:31:1.032:2.299:0.065:211.5:212:2.61:0.48:0.07:0.43:A,12,0.124,C,1,0.010,T,18,2.165:18,12 0|1:37:1.232:2.374:0.054:263.2:263:1.47:8.69:0.06:0.05:A,16,1.160,T,21,1.214:21,16 0|0:43:1.423:2.447:0.047:0.0:98:0.20:0.83:0.45:0.00:A,1,0.010,T,42,2.437:42,1 0|1:40:1.323:3.393:0.075:280.5:281:1.95:2.36:3.47:0.27:A,17,1.175,T,23,2.219:23,17
1 758663 . CGCC TTAG 0/0:27:0.893:0.296:0.000:0.0:90:5.15:0.85:3.67:0.01:27,0 0/1:21:0.699:0.234:0.000:2333.1:353:0.93:2.17:2.36:0.00:9,12 0|0:35:1.166:0.370:0.000:0.0:108:3.97:3.43:4.75:0.00:34,0 0|1:33:1.099:0.375:0.000:2820.8:447:0.07:8.69:0.53:0.00:17,15 0|1:23:0.766:0.232:0.000:1860.0:382:0.85:0.17:0.09:0.00:13,10 0|0:23:0.761:0.255:0.000:0.0:75:1.51:2.59:0.78:0.00:22,0 0|1:18:0.596:0.215:0.000:1686.8:275:0.00:2.17:0.10:0.00:9,9
</code></pre>

<p>i want to filter out everything that comes after the genotype and have an output like below </p>

<pre><code>#CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
1 736689 . T A         0/0     1/0     0|0     0|1        0|1     0|0   0|1
1 758663 . CGCC TTAG   0/0     0/1     0|0     0|1        0|1     0|0   0|1
</code></pre>

<awk>
Filter out other character after the genotype
# Filter out other character after the genotype

(Asked by: username_0 on 2019-09-30)

Is it possible to filter out all the characters that come after the genotype, for example, I have a data 
#CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
1 736689 . T A 0/0:37:1.224:2.367:0.054:0.0:108:0.00:4.75:0.53:0.00:T,37,2.367:37,0 1/0:33:1.099:3.320:0.091:358.5:359:0.59:4.34:0.59:0.08:A,15,1.149,T,18,2.171:18,15 0|0:30:0.999:1.314:0.033:0.0:87:0.00:1.16:0.00:0.00:T,30,1.314:30,0 0|1:31:1.032:2.299:0.065:211.5:212:2.61:0.48:0.07:0.43:A,12,0.124,C,1,0.010,T,18,2.165:18,12 0|1:37:1.232:2.374:0.054:263.2:263:1.47:8.69:0.06:0.05:A,16,1.160,T,21,1.214:21,16 0|0:43:1.423:2.447:0.047:0.0:98:0.20:0.83:0.45:0.00:A,1,0.010,T,42,2.437:42,1 0|1:40:1.323:3.393:0.075:280.5:281:1.95:2.36:3.47:0.27:A,17,1.175,T,23,2.219:23,17
1 758663 . CGCC TTAG 0/0:27:0.893:0.296:0.000:0.0:90:5.15:0.85:3.67:0.01:27,0 0/1:21:0.699:0.234:0.000:2333.1:353:0.93:2.17:2.36:0.00:9,12 0|0:35:1.166:0.370:0.000:0.0:108:3.97:3.43:4.75:0.00:34,0 0|1:33:1.099:0.375:0.000:2820.8:447:0.07:8.69:0.53:0.00:17,15 0|1:23:0.766:0.232:0.000:1860.0:382:0.85:0.17:0.09:0.00:13,10 0|0:23:0.761:0.255:0.000:0.0:75:1.51:2.59:0.78:0.00:22,0 0|1:18:0.596:0.215:0.000:1686.8:275:0.00:2.17:0.10:0.00:9,9

i want to filter out everything that comes after the genotype and have an output like below 
#CHROM POS ID REF ALT FATHER MOTHER DAUGHTER1 DAUGHTER2 DAUGHTER3 SON1 SON2
1 736689 . T A         0/0     1/0     0|0     0|1        0|1     0|0   0|1
1 758663 . CGCC TTAG   0/0     0/1     0|0     0|1        0|1     0|0   0|1

**Tags:** awk

---

## 1 answers

### Answer by username_1 on 2019-09-30. Score: 3 | Accepted answer

Using sed:
sed 's,\([01][/|][01]\):[^ ]*,\1,g' file
#    ^  ^               ^     ^  ^   
#    |  |               |     |  *--- applies to all found pattern
#    |  |               |     *------ print the content inside the parenthesis
#    |  |               *------------ any character except a space
#    |  *---------------------------- the pattern to be kept
#    *------------------------------- substitution

You also may want to format the output using column command:
sed 's,\([01][/|][01]\):[^ ]*,\1,g' file | column -t
#CHROM  POS     ID  REF   ALT   FATHER  MOTHER  DAUGHTER1  DAUGHTER2  DAUGHTER3   SON1  SON2
1       736689  .   T     A     0/0     1/0     0|0        0|1        0|1        0|0   0|1
1       758663  .   CGCC  TTAG  0/0     0/1     0|0        0|1        0|1        0|0   0|1

Note the comma separators in the sed command can replaced with other characters typically "/"


---

