grep out condition and add the values of the grep value

0

I have a scenario that a csv file has the values of :

abcd FAILURE 7

abcd SUCCESS 12

efgh SUCCESS 3

efgh FAILURE 5

mnop SUCCESS 6

mnop SUCCESS 4

abcd FAILURE 5

efgh SUCCESS 2

mnop SUCCESS 1

abcd FAILURE 7

mnop SUCCESS 3

abcd FAILURE 5

Initial grep with abcd/efgh/mnop with failure or success condition then i need a value of the matching conditions addition

i need the required output like this please help me

for example :

abcd FAILURE 7

abcd FAILURE 5

abcd FAILURE 7

abcd FAILURE 5

--------------------

abcd FAILURE **24**

abcd SUCCESS 12

------------------

abcd SUCCESS **12**

but i dont want to give any static string in condition.

thanks in advance.

manu2711

Posted 2014-02-06T11:30:38.880

Reputation: 21

i dont know which string consist in the csv file so cannot give the static string in the grep – manu2711 – 2014-02-06T11:42:36.327

Answers

0

Using grep -c option to count occurences of a search-string. echo outputs the text and uses a sub-shell for the grep count.

echo "abcd FAILURE $(grep -c "abcd FAILURE" filename)" 
echo "abcd SUCCESS $(grep -c "abcd SUCCESS" filename)" 

suspectus

Posted 2014-02-06T11:30:38.880

Reputation: 3 957

0

May be you want something like this:

awk '
BEGIN {
    fail = suc = 0
}
$2 == "FAILURE" {
    fail += $3
    next
}
$2 == "SUCCESS" {
    suc += $3
}
END {
    printf "%s:%s\n%s:%s\n", "SUCCESS",suc,"FAILURE",fail
}' inputFile

Output with you file:

SUCCESS:31
FAILURE:29

jaypal singh

Posted 2014-02-06T11:30:38.880

Reputation: 2 134