How can I get the length of an array in awk?

前端 未结 8 1133
时光取名叫无心
时光取名叫无心 2020-12-03 04:22

This command

echo \"hello world\" | awk \'{split($0, array, \" \")} END{print length(array) }\'

does not work for me and gives this error m

8条回答
  •  旧巷少年郎
    2020-12-03 04:50

    sample on MacOSX Lion to show used ports (output can be 192.168.111.130.49704 or ::1.49704) :

       netstat -a -n -p tcp | awk '/\.[0-9]+ / {n=split($4,a,"."); print a[n]}'
    

    In this sample, that print the last array item of 4th column : "49704"

提交回复
热议问题