Quantcast
Channel: Active questions tagged bash+awk - Ask Ubuntu
Viewing all articles
Browse latest Browse all 102

how to split a string from a column using awk

$
0
0

I am a noob in Linux. I have a file like this:

 col1                                  col2   col3 ID1234567-DNA_A01 chr1_10203040_T/C   gene   0 ID1234568-DNA_A02 chr1_10203050_T/A   gene   0 ID1234569-DNA_A03 chr1_10203060_A/G   gene   0 ID1234570-DNA_A04 chr1_10203070_C/T   gene   0

I want to use only the first column and divide each line into 4 columns:

 #CHROM  POS      REF  ALT 1       10203040  T    C 1       10203050  T    A 1       10203060  A    G 1       10203070  C    T

I tried to make:

  awk 'BEGIN{OFS="\t";FS="\t"; print"#CHROM","POS","REF","ALT"} | cut -d'' -f2- {print  substr($1,4,1),substr($1,6}' old_file > new_file

I know I did wrong, but any suggestion would be helpful!Thanks


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>