Results 1 to 3 of 3
Hello,
I have this problem:
I need a bash script that will do this:
Input file: rating.txt
rating.txt looks like this:
name1;C;13;comments
name2; A;20 ;comments
name15; B;26 ; comments
name16; ...
- 03-25-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 12
Script help
Hello,
I have this problem:
I need a bash script that will do this:
Input file: rating.txt
rating.txt looks like this:
name1;C;13;comments
name2;A;20;comments
name15;B;26; comments
name16;B;6; comments
name16;B;25; comments
etc.
A, B, C etc. means version
13, 20, 26 etc. means points
rating.txt will always look like that, white spaces count is irrelevant.
And I need the script to save the text file for each version that will look like this:
a.txt:
0-4 : 0
5-9 : 0
10-14 : 1
Mean value: 13/1
b.txt:
0-4 : 0
5-9 : 1
10-14 : 0
15-19 : 0
20-24 : 0
25-30 : 2
Mean value: 57/3
the same for c.txt etc..
My biggest problem is that I have no idea how to print those intervals (step=5) to respective output files and add to each interval how many names acheived respective points..
Thanks a lot for any help!
- 03-25-2008 #2Just Joined!
- Join Date
- Mar 2008
- Posts
- 12
Does anyone at least know how to get the Mean value for each version? Thanks in advance.
- 03-25-2008 #3
This is a pretty simple problem, but not with Bash, unfortunately. Basically, the easy way to do this would be to use associative arrays (aka hash arrays/tables). In this data structure, you can take, for instance, a string and map it to some value. You could have a few maps, one to the total, one to the number encountered so far, and one that mapped to an array of the exact variables. The problem is that Bash does not provide associative arrays.
Fortunately, you can emulate this behavior, in your case. Here's how.
We will use Bash arrays. You will need to write a function that takes a string and returns a corresponding number. Since you're using letters, this is easy: "A" => 0, "B" => 1, etc.
You can now use arrays, where you translate each letter to a numeric index. You can learn about Bash arrays at:
http://www.tldp.org/LDP/abs/html/arrays.html
Note that because Bash arrays will not remember keys, you will need to do this yourself. So maybe one more array, and whenever you encounter a new letter, you add it to this array.
Does this make sense?DISTRO=Arch
Registered Linux User #388732


Reply With Quote