AWK's arrays aren't actually multidimensional. The index comma notation simply concatenates its arguments using the string value in the variable SUBSEP (the default value can vary from one AWK implementation to another). ar[A,B] is equivalent to ar[A SUBSEP B]. So if you only want the member whose index is the value of A, simply use ar[A].
You know, it's entirely possible I still don't understand what you really want. You never posted any matching output data for your input data, and the logic you posted wasn't what you wanted either, so I'm still guessing.
Please post a sample of output data that matches your input data so I can properly see the correlation.
Quote:
Originally Posted by chrisjorg
Ok,
but why do you not do like in the first script:
[/quote] Because you don't get your zeroes that way. If you set A[1]=5, and A[9]=6, for(X in A) gets you 1, then 9, not 1 2 3 4 5 6 7 8 9. awk arrays are sparse.
Quote:
Would you not need to correlate your variables A, B to the array BIN?
They are correlated to the array:
But because you want zero values, I have to loop through everything that might be in the array, not just everything that is. So I record the lowest and highest values of the array indexes, and print everything between them. Everything completely absent becomes a zero. This also makes the output ordered exactly how you want, where it might not be otherwise.
Hmm. Another thing, it might be printing blanks instead of zeroes for empty bins. Adding a zero to it should force it into a number no matter what.
---------- Post updated at 01:33 PM ---------- Previous update was at 01:13 PM ----------
Okay, from your question in your other thread, I'm guessing that for each rho-range, you want phi values between the minimum and maximum for that range, not the global maximums in general?
Please confirm or deny.
Or better yet, show example output!!
---------- Post updated at 01:43 PM ---------- Previous update was at 01:33 PM ----------
This should only print zeroes between two values, not extra ones at the 'edges'. I test explicitly for "" to avoid the 999999 nonsense...
Last edited by Corona688; 02-17-2012 at 03:55 PM..
I'm not upset about any criticism. My program did have a lot of bugs, but that's unfortunately to be expected when I have no way to test them -- I can run them, but so what, they work to my understanding of your question, not yours. Without a good example of what it should be outputting I've been grasping at straws. Three bad guesses and counting.
The example output you originally posted had nothing to do with the example input, so wasn't much help; all that demonstrates is that you want it printing rows of three numbers, not which three numbers.
Please save us both days of trouble by picking(or inventing) a few lines of input that clearly illustrate the logic you want, work them out in your head, and show what they'd output. Please.
Last edited by Corona688; 02-17-2012 at 04:36 PM..
I mean, what I posted before is exactly what I want.
But no worries, I am quite satisfied with the first script you wrote.
Let us just leave it here.
Thanks for all the help!
The last modified script you posted is
good except it doesn't stop looping over B:
Code
Input
Output: ---------- Post updated at 05:15 PM ---------- Previous update was at 05:12 PM ----------
---------- Post updated at 05:16 PM ---------- Previous update was at 05:15 PM ----------
Going back to script.awk
I would like my data to have a newline each time
a new bin is output, is this possible?
Example output ---------- Post updated at 05:15 PM ---------- Previous update was at 05:15 PM ----------
If this is too complicated, then don't worry about it!
Hello,
Since I m new to shell, I had a hard time to sought out this problem.
I have a log file of a utility which tells that batch files are successful with timestamp. Given below is a part of the log file.
2013/03/07 00:13:50 Apache/1.3.29 (Unix) configured -- resuming normal operations... (12 Replies)
I have a single file that looks like this:
1.62816
1.62816
0.86941
0.86941
0.731465
0.731465
1.03174
1.03174
0.769444
0.769444
0.981181
0.981181
1.14681
1.14681
1.00511
1.00511
1.20385
1.20385 (2 Replies)
I have a large tab delimited text file with 10 columns
for example
chrM 412 A A 75 0 25 2 ..,AGAATt II
chrM 413 G G 72 0 25 4 ..t,,Aag IIIH
chrM 414 C C 75 0 25 4 ...a,.. III2
chrM 415 C T 75 75 25 4 TTTt,,,ATC III7
At... (4 Replies)
Hi,
I want to perform a task using shell script. I am new to awk programming and any help would be greatly appreciated.
I have the following 3 files (for example)
file1:
Name count Symbol
chr1_1_50 10 XXXX
chr3_101_150 30 YYYY
File2:
Name ... (13 Replies)
I’m new to Linux script and not sure how to filter out bad records from huge flat files (over 1.3GB each). The delimiter is a semi colon “;”
Here is the sample of 5 lines in the file:
Name1;phone1;address1;city1;state1;zipcode1
Name2;phone2;address2;city2;state2;zipcode2;comment... (7 Replies)
Help plz
Does any one have any idea how to compare interval ranges of 2 files.
finding 1-4 (1,2,3,4) of input2 in input1 of same key "a" values (5-10, 30-40, 45-60, 80-90, 100-120 ). Obviously 1-4 is not one of the range with in input1 a. so it should give out of range.
finding 30-33(31,32,33)... (1 Reply)
I need "awk solution" for simple counting!
File looks like:
STUDENT GRADE
student1 A
student2 A
student3 B
student4 A
student5 B
Desired Output:
GRADE No.of Students
A 3
B 2
Thanks for awking! (4 Replies)
I want a shell script which extract data from a log file which contains date and time-wise data and i need the data for a perticular interval of time...what can i do??? (3 Replies)