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
Microsoft Word 2003, save as is grayed out
Install Windows XP on a Linux Notebook
XP language
Exchange Server keeping Messages In Queue
In a SQL Server 2008 Express stored procedure can you return a rowset and an output parameter?
Text count in excel worksheet
VERY URGENT: Exchange 2003 Enterprise Edition - lost E00.log file
Help with RewriteRule
Closing Computer Management (MMC) creates an error: Application popup: mmc.exe
"Connection failed because of a problem with clock synchronization"