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
Smartphones & Outlook
Agent Policy in McAfee
List of folder security rights
Batch file in XP or 2003 to delete ALL files AND folders in a specified directory
sql dts failure DBNETLIB connectionread general network error
Blocking a USB port on my computer running window XP SP2
xml image gallery scroll
Error during Exchange 2007 Install
How to clone a laptop SATA HDD with an external SATA HDD connected via USB?
How to isntall the ODBC DSN for Symantec Endpoint