Using NR in AWK

Hi ,i need to loop through records and print only specific column.
How do i that using NR

I have tried the following code
If i give NR==1 or NR==2,i am able to print the specific column,but if use NR==$i and loop it ,i am not able to print

while [ $i -le $Norec ]
                do
                echo  -e "` awk 'NR==$i { print $2}' stat.txt` "   
                echo  -e "` awk 'NR==$i { print $4}' stat.txt`" 
done

please suggest if there other alternatives to print specific column for each record

Thanks in advance

 
awk -v colno=$i ' if(NR==colno){print $2}' stat.txt

Utilities like awk are efficient when run on batches of data, but take time to load and start, so running multiple instances of awk per loop to process individual lines is extremely inefficient. Imagine only being able to say one word per phone call.

What are you actually trying to do? There may be simpler a way that's hundreds of times faster.

itkamaraj,

i have used your code ,but i am not able to get the desired output.

My requirement is that i need to go through multiple records in a text file and print specific column.

corono688,
Please suggest any alternatives

Thanks in advance

before asking suggestion, why cant you put the example input and required output file and the logic which u tried ?

Fixing your code will mean rewriting more than just your awk statements. I need to see your code, or at least a complete explanation of what your script's trying to do.

The details of input file

student1 male 1year ECE
student2 female 1year EEE
STUDENT3 MALE 2YEAR CSE

nostud will contain the no of records in inpur file.
I need to select each student .For that i have used the first while loop.

In the second while loop i need to print some extra columns along with the ones in input file.
The second loop will be running for no of records required which is an user input.

j=1
while [ $j -le $nostud ]
        do
                i=1
                while [ $i -le $Norec ]
                do
                echo  -e "` awk 'NR==$j { print $2}' subaccount.txt` \c"        
               #some other code to generate some columns
               i=i+1
done
j=j+1
done

My question is that how do i print details available in input file to the output file
for each record generated for as tudent some columns must be picked up from the input file.
Hope thuis clear.
Thanks in advance