How to call the split function in awk to split the string into "\."?

How to use split function to split by "\."?

For example, first consider splitting into::

 echo "03:26:12" | awk '{split($0,a,":"); print a[3] a[2] a[1]}' 

What produces this conclusion:

 122603 

But if the input line is instead:

 echo "03\.26\.12" | awk '{split($0,a,???); print a[3] a[2] a[1]}' 

With the desired output:

 122603 

What should be ??? ?

+6
source share
2 answers

You must hide both characters:

 echo "03\.26\.12" | awk '{split($0,a,/\\\./); print a[3] a[2] a[1]}' 

Result:

 122603 
+8
source
 echo "03\.26\.12" | awk '{split($0,a,"\\\."); print a[3] a[2] a[1]}' 

This gives the same result.

+3
source

Source: https://habr.com/ru/post/911684/


All Articles