I am beginner in awk
awk 'BEGIN{for(i=1;(getline<"opnoise")>0;i++) arr[i]=$1}{print arr[20]}'
In the above script, opnoise is a file, I am reading it into an array and then printing the value corresponding to index 20. Well this is not my real objective, but I have posted this example to describe the problem.
The problem is when I execute the script there is no activity(no error, just a blank) and the body i.e, the print statement, execute only when I hit "ENTER" for the second time. Also gawk does not exit to command prompt automatically, I have to hit CTRL+C to exit and awk gets displayed while exiting.
Here is what happens,
user@server ~/folder
$ awk 'BEGIN{for(i=1;(getline<"opnoise")>0;i++) arr[i]=$1}{print arr[20]}'
684
awk
user@server ~/folder
$
Actually this what I am trying to do. I need to use the values in the array to remove certain records in file opwflightno and make a new file opwonoise. But awk is not executing beyond BEGIN. I had posted above simple example to describe the problem.
awk 'BEGIN {for(i=1;(getline < �opnoise�)>0; i++) arr=$1}{for(j=1; j<=i; j++){if(arr[j]!=$1){print $0}}}' opwflightno > opwonoise