Quote:
1st question:
In line 7 (and 20): What does "f3" stand for? Is it the overall variable result after the calculations? Why "" after?
|
"f3" is just a variable but my thinking was 'field 3'. So it is used to store which items from field 3 will be stored.
f3 is set to "" so as to clear it to nil for each line being investigated.
Quote:
2nd question:
In line 19: Does p[2] and p[3] refer to "6"/"7" and "8"/"15" respectively in field 3 line 2 for example? Why don't call them p[1] and p[2] instead of p[2] and p[3] respectively?
If they do, I am a bit confused with the "[ -]" in line 15.
"[ -]" doesn't mean "the number before the -"?
|
"p" is the array storing the items from each field 3, stored in c3 (column 3) which is separated by ";", and its items are split on EITHER a space or a dash, [ -].
I will demonstrate with an example:
Code:
AGE 6-8 text 1.; AGE 7-15 text 2.
The above is from one of your field 3 examples when using FS = "\t*" (which by the way means zero or more tabs so should probably be FS = "\t+" as each field will have at least one tab as separator.
We then split this on the semi-colon and store values in "c3":
Code:
n = split($3,c3,";")
In this example the output is like so:
Code:
n = 2
c3[1] = AGE 6-8 text 1.
c3[2] = AGE 7-15 text 2.
Now inside the for loop we split again as follows:
Code:
split(c3[i], p, "[ -]")
And again, based on the example and i = 1 the values will be:
Code:
p[1] = AGE
p[2] = 6
p[3] = 8
p[4] = text
p[5] = 1.
From this we see that the values we are interested in are stored in the array indices 2 and 3.
So now when we look at the following code:
Code:
if( p[2] >= c1[1] && p[2] <= c1[2] && p[3] >= c1[1] && p[3] <= c1[2])
So again, looking at the full line example:
Code:
5-10 A2 AGE 6-8 text 1.; AGE 7-15 text 2. SIZE 1-20 text 3.; SIZE 9-18 text 4.
The values in the "if" would be:
Code:
if( 6 >= 5 && 6 <= 10 && 8 >= 5 && 8 <= 10 )
As the above is true we now assign the piece of column 3 (c3[i] where i = 1) that we are looking at to our variable "f3":
Code:
f3 = f3 (f3?"; ":"")c3[i]
Here we use the ternary (?:) operation to check if f3 is empty and if it is simply assign c3[i] and if not the place "; " before c3[i]
I will let you read all of this and see if it helps with field 4. Let me know how you go