User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,427 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,584 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1696 | Replies: 1
Reply
Join Date: Jan 2007
Posts: 1
Reputation: bucci is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bucci bucci is offline Offline
Newbie Poster

Help [Need Help] shell scripting count data in files

  #1  
Jan 24th, 2007
hi experts,

i'm new on scripting on sun solaris 8 sparc, need some advices. i have some data in a file like :

20061221 163826.485 20061221 163925.144 058.659 6123456789012 00000E8A 047 08 002 465 00010022 510105642138069
20061221 163915.163 20061221 163925.336 010.173 6123456789012 00000F4F 037 02 002 999 00010022 510103242202784
20061221 163852.363 20061221 163925.549 033.186 6123456789012 00000EED 040 06 002 999 00010022 510105832049518
20061221 163803.035 20061221 163925.708 082.673 6123456789012 00000E26 010 08 002 800 00010022 510105732551708
20061221 163921.293 20061221 163925.787 004.494 6123456789012 00000F6C 039 02 002 999 00008001 510105642169788
20061221 163650.185 20061221 163926.027 155.842 6123456789012 00000D16 051 08 002 465 00008001 510105732672986
20061221 163923.325 20061221 163926.381 003.056 6123456789012 00000F75 062 02 002 123 00008001 510103342614669

example of the data :

20061221 163923.325 20061221 163926.381 003.056 6123456789012 00000F75 062 02 002 123 00008001 510103342614669

underline is shortcode and bold is causes code

the filename is in date format like "2006122001.TDR" and the file generated each hour like 2006122002.TDR,2006122003.TDR,etc. the file log found at /log/TDR/

--> i want to check into the file (e.g. 2006122000.TDR) line by line and get how much shortcode having causes code "00008001".

--> generate it into a file (e.g. 2006122000.log) per hour the info which shortcode having cause code "00008001"

--> count per shortcode how much each short code having causes code "00008001". (e.g. 123 count 20, 465 count 30,etc)

--> send it through sms using syntax : msggen msggen_SMClient.txt 1 "[01234356789]" "[Result of counted data]"

--> the script will running in background and check for the previous hour log file


please advices help to build simple script for this case

Thank you so much


Regards,

bucci
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2004
Posts: 177
Reputation: jim mcnamara is on a distinguished road 
Rep Power: 5
Solved Threads: 9
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: [Need Help] shell scripting count data in files

  #2  
Jan 26th, 2007
This will generate a report like you asked for.
nawk '
     {	shortcode[$11]=$11	
        causecode[$12]=$12	
        result[$11 $12]++
     }
	END{ for( short in shortcode)
	  {
		for(cause in causecode)
		{
			if(result[short cause])
			{
				print short, "count", cause, result[short cause]
			}
		}

	  }
	} ' filename

You will have to write another small script that runs under cron (once every hour) and calls the above nawk code with the correct file name.
awk on Solaris is crippled, you have to use nawk to get the features above.

I don't know sms, so someone else will have to help.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:15 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC