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.
Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".
The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!
In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.
So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.
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 a simple example to describe the problem.
sorry about the curlies - here's a newER version with comments:
awk '
# dealing with the FIRST specified file - opnoise
# for every line/record in the FIRST file, create an array (arr) indexed by FNR
# with the value of the first field ($1)
# go to the next record/line (next)
FNR==NR {arr[FNR]=$1; next}
# Here we're dealing with the SECOND file specified on the command line - (opwflightno)
# if the array (arr) cell indexed by FNR equal the value of the first field ($1) -
# print the entire record/line.
$1==arr[FNR]
' opnoise opwflightno > opwono
I am beginner, and would like to know the following
Does the command read the files one by one, or does it read it simultaneously?
How does it know which command is for which file?
How does this command work without any curlies, if statement or print statement.
In my case opnoise has 1000 unique records(2, 7, 12 and so on ) with just one field, where as opwflightno has 4560500 records with repetitive first field, and other fields of course. For example, it has 5000 records with first field value 2, 3000 records with first field value 3, 1200 records with first field 7 and so on.
*How do I get all the records from opwflightno that do not have first field equal to the first field of opnoise? In reference to the above example I would want all the records with first field equal to 3 and disregard the ones with first field 2 and 7.
---------- Post updated at 05:47 PM ---------- Previous update was at 05:23 PM ----------
What values are assigned to array f[$1]? I understand its indexed by $1 of file opnoise. Or I guess the index does not matter in this case, its just creates an array with all the records in $1 of file opnoise. Am I thinking right? Could you please further explain the meaning of f1[$1].