Solved

Shell - Command to filter and count lines

Posted on 2014-02-18
6
309 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now