I am experiencing some problems with a for cycle in bash, in combination with awk; I am running it in Ubuntu 14.04. This is the script I am writing:

```
#!/bin/bash

L=99;

for j in 1 2 3
do

 awk -v J=$j '

  BEGIN {active=0}
  /Sweep 6/ {active=1}
  /Energy/ {
  a=substr($6,1,length($6)-1);
  if ((active) && (a==J)) {
   getline;
   getline;
   getline;
   print a+1, $5
  }
 }
'

done

```

Without entering into the details of the text file I am processing, what the script does is just running what is in the cycle for j=1, instead of j=1, 2 and 3. Where is the problem?

Thanks in advance!