2

I am looking for help in below file. There are clients in column 1 which can be part of one or multiple groups. Their status can be either Failed, succeeded or interrupted. I want only those client who is not having any entry of succeeded.

Example

My file is as below

RBCSREXC04 AUTO_RERUN_RBC_DAILY succeeded
RBCSRTM03 AUTO_RERUN_RBC_DAILY succeeded
RBCVMAPPPROD01 AUTO_RERUN_RBC_DAILY succeeded
RBCVVMAPPDEV02 AUTO_RERUN_RBC_DAILY succeeded
E6-RBC-SQL-06 AUTO_RERUN_RBC_DAILY succeeded
E6-ODI-Prod-01 AUTO_RERUN_RBC_DAILY succeeded
GSIERBC2004 AUTO_RERUN_RBC_DAILY succeeded
GSIERBC3008 AUTO_RERUN_RBC_DAILY succeeded 
RBCSRTM03 D_RBC_VM_DUBLIN_E6 failed
RBCSREXC04 D_RBC_VM_DUBLIN_E6 failed
GSIERBC3008 D_RBC_VM_DUBLIN_E6_1 interrupted
E6-ODI-Prod-01 D_RBC_VM_DUBLIN_E6_1 failed
RBCVVMAPPDEV02 D_RBC_VM_DUBLIN_E6_1 failed
E6-RBC-SQL-06 D_RBC_VM_DUBLIN_E6 failed
RBCVMAPPPROD01 D_RBC_VM_DUBLIN_E6 failed
RBCSRCV01 D_RBC_VM_DUBLIN_E6 failed

Below is the Expected Output

RBCSRCV01 D_RBC_VM_DUBLIN_E6 failed
6
  • CSV? Or tab or space separated? Commented Apr 10, 2020 at 12:34
  • And what have you tried? Commented Apr 10, 2020 at 12:36
  • Why isn't b group2 failed in your output? Or others? Is it just one random matching line per group? Commented Apr 10, 2020 at 12:37
  • @Shawn its space-separated. Commented Apr 10, 2020 at 12:38
  • @Shawn -Because b group2 failed got success in last line Commented Apr 10, 2020 at 12:38

2 Answers 2

1

You could maintain two arrays with awk for the "good" and the "bad" entries where the array index is the first column and only print the "bad" ones for which no entry in the "good" array exists.

awk '
  $3=="succeeded"{ good[$1] }  # we only need the index here
  $3=="failed" || $3=="interrupted"{
    if ($1 in bad){ 
      bad[$1]=bad[$1] ORS $0 # append this line to existing entry
    } else {
      bad[$1]=$0             # save the line
    }
  }
  END{
    for (i in bad)
      if (!(i in good))print bad[i]
  }
' file
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks, Freddy for your help but in your script, I am facing issue like if the client gets succeeded in other groups then it shows it as Failed. But I want that if a client gets successful in the same or any other group, it should not come in output. I want only those clients who have single or multiple entries of Failed or interrupted with no success.
Freddy, I have updated my question with a new example. I want only those clients in output who are not at all success even once in any of the group.
Thanks, @Freddyfor your help but I am facing the same issue, if the client gets succeeded in any other group then it does not filter it but if it gets succeeded in the same group then it does. I want if the client gets succeeded in any of the group then it should not be in output –
I have updated my question with the original file from my server.
I replaced success with succeeded in my script.
|
1
sed -n '/succeeded/ s,\(.*\) .* succeeded$,\1,p' status.csv | grep -v -f - status.csv

Explanation: the sed produces list of 'x' which has success status (in any group). The grep will drop (because of -v) them from status.csv (the -f - means grep obtains patterns from stdin (equals sed's stdout)).

5 Comments

Thanks, UZSOLT for your help but in your script, I am facing issue like if the client gets succeeded in other groups then it shows it as Failed. But I want that if a client gets successful in the same or any other group, it should not come in output. I want only those clients who have single or multiple entries of Failed or interrupted with no success.
Thanks, @Uzsolt for your help but I am facing the same issue, if the client gets succeeded in any other group then it does not filter it but if it gets succeeded in same group then it does. I want if the client gets succedded in any of the group then it should not be in output
@GURUSINGH success -> succeeded Please don't edit many times your question because it's impossible answer it. Please be exact.
Thanks @uzsolt. I am sorted now. Please let me know if we can do achieve the same thing in Powershell also
I don't know Powershell. Maybe it should be an another question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.