0

I would like to replace "colon" from each columns except from first column as it is.

]chr9:67290502]N SUPP_VEC=011 SVLEN=0 SVTYPE=TRA 0 0 0 0/1:NA:58745598:23,0:--:.:TRA:BND00068094:NA:NA:chr10_8544904-chr9_67290502 ./.:NA:58745598:0,4:--:.:TRA:126434_2:NA:NA:chr10_8544903-chr9_67290501

desired output

]chr9:67290502]N SUPP_VEC=011 SVLEN=0 SVTYPE=TRA 0 0 0 0/1NA5874559823,0--.TRABND00068094NANAchr10_8544904-chr9_67290502 ./.NA587455980,4--.TRA126434_2NANAchr10_8544903-chr9_67290501

tried:

sed 's/(chr*.)*.[^: ]//g'

NOTE: don't need to define the columns as ":" are not fixed after first four columns, it can be anywhere.

0

2 Answers 2

2

If you're thinking in terms of "columns", you definitely want awk to parse your stuff. Ideally, you have acces to GNU awk.

Try this:

awk '{for(x=2;x<=NF;x++){gsub(":","",$x)}}1'

Test case:

$ echo "]chr9:67290502]N SUPP_VEC=011 SVLEN=0 SVTYPE=TRA 0 0 0 0/1:NA:58745598:23,0:--:.:TRA:BND00068094:NA:NA:chr10_8544904-chr9_67290502 ./.:NA:58745598:0,4:--:.:TRA:126434_2:NA:NA:chr10_8544903-chr9_67290501" | awk '{for(x=2;x<=NF;x++){gsub(":","",$x)}}1'
]chr9:67290502]N SUPP_VEC=011 SVLEN=0 SVTYPE=TRA 0 0 0 0/1NA5874559823,0--.TRABND00068094NANAchr10_8544904-chr9_67290502 ./.NA587455980,4--.TRA126434_2NANAchr10_8544903-chr9_67290501
3
  • But what if field one, as awk knows it, contains two colons, or zero?
    – Jeff Schaller
    May 8, 2019 at 21:35
  • @JeffSchaller Field one is not even referenced in this script, so awk just passes over it. May 8, 2019 at 21:43
  • Thank you, its wok perfectly !!
    – RKK
    May 9, 2019 at 13:48
0

Tried with below sed command and it worked like charm

command: sed "s/://2g"`

output

Command with input : echo "]chr9:67290502]N SUPP_VEC=011 SVLEN=0 SVTYPE=TRA 0 0 0 0/1:NA:58745598:23,0:--:.:TRA:BND00068094:NA:NA:chr10_8544904-chr9_67290502 ./.:NA:58745598:0,4:--:.:TRA:126434_2:NA:NA:chr10_8544903-chr9_67290501"| sed "s/://2g"

Output

]chr9:67290502]N SUPP_VEC=011 SVLEN=0 SVTYPE=TRA 0 0 0 0/1NA5874559823,0--.TRABND00068094NANAchr10_8544904-chr9_67290502 ./.NA587455980,4--.TRA126434_2NANAchr10_8544903-chr9_67290501

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .