Whoops, I forgot the END... Thanks rosehosting.com !
Can I ask you another question related to this thread? (maybe I should create a new thread)
Even if it is not necessary now, I am just curious about a detail.
While I was looking for a solution to this problem, I faced another problem to create an array.
For each line of the previous input, I added a field with the number of occurrence of the paired $1 and $2, and wanted to sort the field I just created by descending order using the "asort" function. Then I could have use the classical way to remove duplicates by keeping the first instance.
The problem is I couldn't get the right output after sorting the last field in order to obtain that:
Code:
item1/ref.001/eur/Spa./1
item1/ref.001/eur/Bel./0
item2/ref.002/eur/Ita./0
item3/ref.002/asi/Chi./0
item4/ref.003/afr/Sen./1
item4/ref.003/ame/Can./0
The code I used to sort the last field by descending order:
Code:
BEGIN{FS=OFS="/"}
{occur = array[$1$2]++
line = $0 FS occur
array[occ++] = occ
n = asort(array, "@val_num_desc")
for(i=0; i<=n; i++){
print $0 FS array[i]
}
}
Do you see why it doesn't work?
I am not sure about the array in the asort function.
Can you create an array without using the "split" function?
Thanks !