6

Hi I tried to split columns using awk command where in I have to use two separate characters for splitting the same column "comma and colon"

If My input file is like this

 0/1:121,313:4:99:123,0,104

I used : to split the column

echo "0/1:121,313:4:99:123,0,104" | awk '{split($0,a,":"); print a[2] a[3]}

I am getting this output

121,3134

However I only Need this output

121313

How to separate using both : and , ( Colon and Comma)

And I dont want to use awk -F command cause this is part of larger tab delimited text file which I am workin on.

RonicK
  • 229
  • 2
  • 3
  • 10

1 Answers1

10
awk -F '[,:]' '{ print $2 $3 }' file

By setting the field separator (by means of -F) to "either , or :", we may avoid doing an explicit split() on the data.

Or,

awk -F '[,:]' '{ print $2, $3 }' OFS='' file

which additionally uses an empty output field separator.

Kusalananda
  • 14,885
  • 3
  • 41
  • 52