Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
For loop 为循环嵌套的AWK;10-89小于9英寸”;_For Loop_Awk_Nested - Fatal编程技术网

For loop 为循环嵌套的AWK;10-89小于9英寸”;

For loop 为循环嵌套的AWK;10-89小于9英寸”;,for-loop,awk,nested,For Loop,Awk,Nested,我试图在AWK中使用嵌套for循环,但似乎遇到了数组和变量的数字比较问题 例如: 创建数组 str[0]="a"; str[1]="b"; str[2]="c"; str[3]="d"; str[4]="e"; str[5]="f"; str[6]="g"; str[7]="h"; str[8]="i"; str[9]="j"; str[10]="k"; str[11]="l"; str[12]="m"; str[13]="n" 打印内容,每行一个索引,每行缩进 for(i in str) {

我试图在AWK中使用嵌套for循环,但似乎遇到了数组和变量的数字比较问题

例如:

创建数组

str[0]="a"; str[1]="b"; str[2]="c"; str[3]="d"; str[4]="e";
str[5]="f"; str[6]="g"; str[7]="h"; str[8]="i"; str[9]="j";
str[10]="k"; str[11]="l"; str[12]="m"; str[13]="n"
打印内容,每行一个索引,每行缩进

for(i in str) {
  printf "index " i ":"
  for(j=0;j<=i;j++) {
    printf "<tab " j ">"
  }
  printf str[i] "\n"
}
for(str中的i){
printf“索引”i:“

对于(j=0;j问题


jIt必须进行字符串比较,而不是数字比较。使用条件
j强制其进行可能的重复
index 0:<tab 0>a
index 1:<tab 0><tab 1>b
index 2:<tab 0><tab 1><tab 2>c
index 3:<tab 0><tab 1><tab 2><tab 3>d
index 4:<tab 0><tab 1><tab 2><tab 3><tab 4>e
index 5:<tab 0><tab 1><tab 2><tab 3><tab 4><tab 5>f
index 6:<tab 0><tab 1><tab 2><tab 3><tab 4><tab 5><tab 6>g
index 7:<tab 0><tab 1><tab 2><tab 3><tab 4><tab 5><tab 6><tab 7>h
index 8:<tab 0><tab 1><tab 2><tab 3><tab 4><tab 5><tab 6><tab 7><tab 8>i
index 9:<tab 0><tab 1><tab 2><tab 3><tab 4><tab 5><tab 6><tab 7><tab 8><tab 9><tab 10><tab 11><tab 12><tab 13><tab 14><tab 15><tab 16><tab 17><tab 18><tab 19><tab 20><tab 21><tab 22><tab 23><tab 24><tab 25><tab 26><tab 27><tab 28><tab 29><tab 30><tab 31><tab 32><tab 33><tab 34><tab 35><tab 36><tab 37><tab 38><tab 39><tab 40><tab 41><tab 42><tab 43><tab 44><tab 45><tab 46><tab 47><tab 48><tab 49><tab 50><tab 51><tab 52><tab 53><tab 54><tab 55><tab 56><tab 57><tab 58><tab 59><tab 60><tab 61><tab 62><tab 63><tab 64><tab 65><tab 66><tab 67><tab 68><tab 69><tab 70><tab 71><tab 72><tab 73><tab 74><tab 75><tab 76><tab 77><tab 78><tab 79><tab 80><tab 81><tab 82><tab 83><tab 84><tab 85><tab 86><tab 87><tab 88><tab 89>j
index 10:<tab 0><tab 1>k
index 11:<tab 0><tab 1>l
index 12:<tab 0><tab 1>m
index 13:<tab 0><tab 1>n
j<=i+0
for(i in str) {
  printf "index " i ":"
  for(j=0;j<=i+0;j++) {
    printf "<tab " j ">"
  }
  printf str[i] "\n"
}