How to split a delimited string into an array in awk?

Mohamed Saligh picture Mohamed Saligh · Nov 4, 2011 · Viewed 475.1k times · Source

How to split the string when it contains pipe symbols | in it. I want to split them to be in array.

I tried

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

Which works fine. If my string is like "12|23|11" then how do I split them into an array?

Answer

Calin Paul Alexandru picture Calin Paul Alexandru · Nov 4, 2011

Have you tried:

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