Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
i dont know which string consist in the csv file so cannot give the static string in the grep – manu2711 Feb 6 '14 at 11:42

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)" 
share|improve this answer

May be you want something like this:

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

Output with you file:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.