LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   files and text files (https://www.linuxquestions.org/questions/linux-newbie-8/files-and-text-files-912535/)

congos 11-08-2011 02:00 PM

files and text files
 
im trying to write a script that will create a text file with names in it and there points for example
evans +1.5
greg +1
john +0.5
etc
the script should output the text file on the screen or to another file which will display how many evans's in the file for example if they are three it should show evans 4.5
any ideas???

colucix 11-08-2011 02:19 PM

Well, you have many alternatives to create the file from a script (echo, printf, here documents and so on). The question is: where the input data comes from? Standard input? Another file?

Regarding the second part a simple awk code will do the sum for you:
Code:

awk '{_[$1] += $2} END{for (i in _ ) print i,_[i]}' file


All times are GMT -5. The time now is 09:43 AM.