LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux script (https://www.linuxquestions.org/questions/linux-newbie-8/linux-script-4175438899/)

pradeep rawat 11-27-2012 06:22 AM

Linux script
 
can anyone help in this
i have a file like
2089,success
2089,failure
2087,failure
2089,success
2087,failure.
i want output like.
2089,success=2,failure=1
2087,success=1,failure=2
thanks

shivaa 11-27-2012 06:45 AM

Wierd! Do you want that when 2089 comes, 2 gets assigned to success and 1 to failure, similarly when 2087 comes, success gets 1 and failure gets 2?
Although it can be managed using a script, but specify that what's purpose of doing this.

pradeep rawat 11-27-2012 06:50 AM

its not assigning its like script should fine unique number from table and sum the number of time success and failure are there in second column.

colucix 11-27-2012 07:12 AM

An awk solution:
Code:

awk -F, '/success/{s[$1]++; a[$1]} /failure/{f[$1]++; a[$1]} END {for ( i in a ) printf "%d,success=%d,failure=%d\n", i, s[i], f[i]}' file


All times are GMT -5. The time now is 10:32 PM.