Solved

Solaris 10 - Shell script

Posted on 2015-01-14
2
190 Views
Last Modified: 2015-01-14
Hi,

I have a big text file (3G) that look like this:

150105 00:04:17                                                             ACTIVATE_SUBSCRIPTION                                                                                COMPLETE                                                                                                                  
150105 00:12:38                                                             ACTIVATE_SUBSCRIPTION                                                                                COMPLETE                                                                                                                  
150105 00:02:36                                                             ACTIVATE_SUBSCRIPTION                                                                                COMPLETE                                                                                                                  

You have in each line 3 columns: a timestamp, type and status.

As you can see in the time stamp part I have a date in the format as YEAR/MONTH/DAY.

What I need is a count for the total of lines I have for each type (in the example lines above is ACTIVATE_SUBSCRIPTION) and for every type a count for each status (in the example above is COMPLETE).

The possible types are:
ACTIVATE_SUBSCRIPTION
CHANGE_IMSI
CHANGE_MSISDN
DEACTIVATE_SUBSCRIPTION
DELETE_CARD
GET_REQUEST_INFORMATION
GET_SUBSCRIPTION_INFORMATION
PUSH_APPLICATIONS
PUSH_FILES
PUSH_FILE_PROFILE
REPUSH_FILES
SIM_SWAP
UPDATE_FEATURES
UPDATE_SUBSCRIPTION

And the possible statuses are:
QUEUED
ONGOING
COMPLETE
COMPLETE_WITH_ERRORS

The timestamp goes through 150105 to 150109.

So the output should look like this:
150105,ACTIVATE_SUBSCRIPTION,QUEUED,<the count of lines like this>
150105,ACTIVATE_SUBSCRIPTION,ONGOING,<the count of lines like this>
.
.
150105,SIM_SWAP,COMPLETE,<the count of lines like this>
.
.
150109,UPDATE_SUBSCRIPTION,COMPLETE_WITH_ERRORS,<the count of lines like this>

A sample of the file is attached.

Pls skip the first 5 lines of the file if possible...

Is this possible to be done?

Tks,
Joao
file-sample
0
Comment
Question by:joaotelles
2 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 40549234
If you have enough RAM, the easiest way is:

    awk 'NR > 5{print $1 "," $3 "," $4}' tstcom.txt | grep -v ',,' | sort | uniq -c

With your data (and 5 dummy lines added to the top, the output is:

    4 150105,ACTIVATE_SUBSCRIPTION,COMPLETE
   3 150109,UPDATE_SUBSCRIPTION,COMPLETE
   1 150109,UPDATE_SUBSCRIPTION,COMPLETE_WITH_ERRORS

If you want it swapped round so that the number is after the text, add

   | awk '{print $2 "," $1}'

to the end of the command line
0
 

Author Comment

by:joaotelles
ID: 40549359
Tks worked just fine!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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