Microsoft
Software
Hardware
Network
Question : 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'
Example:
XXXXXXXXXXXXXXXXXXXXXX$a=1
234:d=fred
:y=alphazX
XXXXXXXXXX
mFAIL
XXXXXXXXXXXXXXXXXXXXXX$d=f
red:a=4321
:y=bravozX
XXXXXXXXXX
mFAIL
XXXXXXXXXXXXXXXXXXXXXX$a=1
234:g=jack
son:y=char
liezXXXXXX
XXXXXmFAIL
XXXXXXXXXXXXXXXXXXXXXX$y=d
elta:a=135
7:d=bobbyz
XXXXXXXXXX
XmFAIL
--------------------------
------
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
Answer : How can I grep, parse lines, and return count by certain fields?
zgrep FAIL file | perl -ne '(/\bd=(\w+)/||/\bg=(\w+)/
) && $c{$1}++;END{print"$_ $c{$_}\n" for keys %c}'
Random Solutions
Inner/Outer join ?
Unexpected login error: Status 3221225659
exchange 2003 - how to mass delete emails from smtp queue
Command Line parameters into CeRunAppAtTime
How can i configure tomcat in my netbeans IDE?
ASP.NET 2.0 login control codebehind
Windows XP Drivers for Sony VAIO FZ140 ?
Can't use NTbackup on ISA Server - Error 11, 12292
running vrrpd daemon
password policy properties are grayed out