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.
First awk , output the second field only. Second awk , choose [_/] as field separator, print the new Header and the fields. $1=$1 triggers reorganisation of fields, which is necessary as we change the output field separator to \t . You may add | column -t to make the columns in line.
You must specify either the -c option to cut by column or -f to cut by fields. (Fields are separated by tabs unless you specify a different field separator with -d. Use quotes (Section 27.12) if you want a space or other special character as the delimiter.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With