[英]How to return all elements of a arrary of split function in awk without making a loop to a ksh arrary?
關於這一點,我需要返回沒有循環的數組拆分函數中的所有元素,但是我不知道這是sintyaxis,我認為:
#!/bin/ksh
set -a MyArray
echo 'hello world' | awk '{
split($0, arrSplit)
print arrSplit[all elements]
}'
有人可以幫助我嗎?
如果要在ksh中設置數組,您需要做的就是
set -A myArray hello world
echo "${myArray[0]}" # => hello
在awk中, split
函數返回產生的元素數。 要遍歷數組,您需要此值
awk '
BEGIN {
n = split("this is a string that I want to split into words", ary)
for (i = 1; i <= n; i++) {
print i, ary[i]
}
}
'
編程有3件事是很難的:給事物起好名字,以及一個錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.