How can I grep, parse lines, and return count by certain fields?

-need a one liner that greps a file for all entries with 'FAIL'
-then it will parse through the lines and return a count for each unique name in field 'd' (note that fields are not always in the same order)
-if field d does not exist, count by field 'g'
If you were to run the one-liner on the above lines, the output should be:
fred 2
jackson 1
bobby 1

-If need be, it is ok to call perl for this execution
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

can you give me the XXXXX values (or are they really XXXX) ?
perl -ne '/FAIL/ && (/\bd=(\w+)/||/\bg=(\w+)/) && $c{$1}++;END{print"$_ $c{$_}\n" for keys %c}'  file
uaMozillaAuthor Commented:
  Is there someway to put a zgrep or something in front of all this so that it works with gzipped files?
zgrep FAIL file | perl -ne '(/\bd=(\w+)/||/\bg=(\w+)/) && $c{$1}++;END{print"$_ $c{$_}\n" for keys %c}'  

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
uaMozillaAuthor Commented:
Perfect. Thanks Ozo.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.