Solved

Shell - Command to filter and count lines

Posted on 2014-02-18
6
311 Views
Last Modified: 2014-02-19
Hi,

I have a list of files:

.
TrafficErrorEvents20140128.9583
TrafficErrorEvents20140212.0604
.
.

that each have several of these lines:

20140218171207#20140218171207#6698072736#MDMD3#mdm1a#1#6698072737#3#ConfigurationName=CP_WIBTSD#ConfigurationVersion=5.2#DestinationAddress=59177388039#IMEI=70306000300926#MSISDN=59177388039#TerminalId=70306000300926#
.
.
20140218171207#20140218171207#6698072742#MDMD3#mdm1a#1#6698072743#3#ConfigurationName=CP_WIBTSD#ConfigurationVersion=5.2#DestinationAddress=59177250681#IMEI=01384100820529#MSISDN=59177250681#TerminalId=01384100820529#


So, what I need is:

A command that would scan these files (something with a wildcard TrafficErrorEvents201401* for example)

And outputs a count of the IMEI=70306000300926 that are equal....

So for example of the lines above I would have:
70306000300926  1
01384100820529  1

Is this something that can be done?

Tks,
Joao
0
Comment
Question by:joaotelles
  • 2
  • 2
  • 2
6 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39868727
If the value in question is always preceeded by "IMEI=" and always terminated with "#MSISDN"
you can try this:

awk -F"IMEI=|#MSISDN" '/IMEI=/ {A[$2]+=1} END {for(n in A) print n,A[n]}' TrafficErrorEvents201401*
0
 
LVL 84

Expert Comment

by:ozo
ID: 39868734
perl -lne '++$c{$_} for /IMEI=(\d+)/g;END{print "$_\t$c{$_}" for keys %c}' TrafficErrorEvents201401*
0
 

Author Comment

by:joaotelles
ID: 39868870
Sorry I forgot to mention, in these files I have a bunch of other diferent lines.. so I get the lines I need I have to filter by MDMD3..

Can you guys add this?

For example on my two lines, I have MDMD3 in both of them.... (#MDMD3#)

20140218171207#20140218171207#6698072736#MDMD3#mdm1a#1#6698072737#3#ConfigurationName=CP_WIBTSD#ConfigurationVersion=5.2#DestinationAddress=59177388039#IMEI=70306000300926#MSISDN=59177388039#TerminalId=70306000300926#
.
.
20140218171207#20140218171207#6698072742#MDMD3#mdm1a#1#6698072743#3#ConfigurationName=CP_WIBTSD#ConfigurationVersion=5.2#DestinationAddress=59177250681#IMEI=01384100820529#MSISDN=59177250681#TerminalId=01384100820529#
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 84

Accepted Solution

by:
ozo earned 350 total points
ID: 39868901
perl -lne '/#MDMD3#/&&/IMEI=(\d+)/&&++$c{$1};END{print"$_\t$c{$_}"for keys%c}' TrafficErrorEvents201401*

or, if #MDMD3# always precedes IMEI=
perl -lne '/#MDMD3#.*IMEI=(\d+)/&&++$c{$1};END{print"$_\t$c{$_}"for keys%c}' TrafficErrorEvents201401*
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 150 total points
ID: 39868924
So there are lines containing "IMEI=" which you want to ignore if they don't also contain "#MDMD3#"?

awk -F"IMEI=|#MSISDN" '/IMEI=/&&/#MDMD3#/ {A[$2]+=1} END {for(n in A) print n,A[n]}' TrafficErrorEvents201401*
0
 

Author Closing Comment

by:joaotelles
ID: 39871401
Tks. Both worked just fine.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question