[Solved] missing date in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] missing date in unix
# 8  
Old 10-02-2012
Thanks, you are on track.This is giving output like by using below code
Code:
$ awk -F "[-,]" '{if(a){if(($3-a) > 1){p=$1","$2",";q="-"$4"-"$5",0";a++;for(i=a;i<$3;i++){a++;print p""i""q;}{print}}else{a=$3;print $0}}else{a=$3;print $0}}' file

SystemName,ComponentName,Date,Count
------------------------------------------------------
Code:
MNP_Message_Gateway,Mg_Message_count,07-AUG-12,42
MNP_Message_Gateway,Mg_Message_count,20-AUG-12,24


but not giving the below missing date(Which is not available in my file).which need to generate missing date automatically with 0 count.
Code:
MNP_Message_Gateway,Mg_Message_count,8-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,9-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,10-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,11-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,12-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,13-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,14-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,15-AUG-12,0--not available in file
--not available in file
MNP_Message_Gateway,Mg_Message_count,16-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,17-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,18-AUG-12,0--not available in file
MNP_Message_Gateway,Mg_Message_count,19-AUG-12,--not available in file--not available in file
----------------------------------------------------------
My O/P would be:
MNP_Message_Gateway,Mg_Message_count,07-AUG-12,42
MNP_Message_Gateway,Mg_Message_count,8-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,9-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,10-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,11-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,12-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,13-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,14-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,15-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,16-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,17-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,18-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,19-AUG-120
MNP_Message_Gateway,Mg_Message_count,20-AUG-12,24

Quick reply must be appriciated.Please let me know if you have any queries.

Last edited by Franklin52; 10-02-2012 at 09:31 AM.. Reason: Please use code tags for data and code samples
# 9  
Old 10-02-2012
Quote:
Originally Posted by rabindratech
...
Quick reply must be appriciated.Please let me know if you have any queries.
Requesting a "quick reply" while waiting for a day or more with your input is a bit strange, as is the input being modified during the quest. Have you tried the suggestion in post #5? It worked for your original input sample. Adapt post #5 yourself to, or try this for, your modified input sample:
Code:
awk     'BEGIN{FS=OFS=","}
         {split($3,B,"-");
          if (NR==1) A=B[1]-1;
          while (B[1]!=++A) {h=sprintf ("%s-%s-%s", A,B[2],B[3]); print $1,$2,h,"0"}
          A=B[1]
          print
         }
        ' file

giving
Code:
MNP_Message_Gateway,Mg_Message_count,07-AUG-12,42
MNP_Message_Gateway,Mg_Message_count,8-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,9-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,10-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,11-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,12-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,13-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,14-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,15-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,16-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,17-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,18-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,19-AUG-12,0
MNP_Message_Gateway,Mg_Message_count,20-AUG-12,24

Are you sure the before last line in your desired output given above is what it should be?

You did not answer my questions a) does your problem span months? b) do month start/end need to be covered?

And, last but not least, is there a reason to constantly ignore moderators' requests to use code tags?

Last edited by RudiC; 10-02-2012 at 09:52 AM..
# 10  
Old 10-02-2012
let say example
-----------------------------------------
systemdate,componentname,date,count
---------------------------------------
a,A_B,1-JAN-08,2
a,A_B,3-JAN-08,2
B,T_K,7-AUG-09,2
B,T_K,11-AUG-09,2
EXPLANATION:

Here correct the output will be below with missing date and available date
a,A_B,1-JAN-08,2
a,A_B,2-JAN-08,0
a,A_B,3-JAN-08,2
B,T_K,7-AUG-09,2
B,A_B,8-AUG-09,0
B,A_B,9-AUG-09,0
B,A_B,10-AUG-09,0
B,T_K,11-AUG-09,2



it need to print for entire year's day starting missing date and available date each system for e.g.
1) for a system will print 1-JAN-08 to till date
2) for B system will print 7-AUG-08 to till date
3)month start/end will be covered for each system
4) display till date for each system from min date available
Logic
if date available then diplay as it is
else (display from min date to till date available for the each system
for example:Mg_Message_count,07-Aug-12,42)
else
display count 0 for example:Mg_Message_count,7-Aug-12,0 ..to till date)
# 11  
Old 10-02-2012
I think you have problem with file re-direction....

try this...

Code:
awk {} file > temp_file
mv temp_file file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the missing date and day in a table?

Hi Am using unix Aix Ksh Have Created table called vv and i have inserted two date Select * from vv; Output :- New_date 21/02/2013 24/02/2013 I have tried Using One query but Unsuccessful so far.. SELECT l.new_date + '1 day' as miss from vv as l (7 Replies)
Discussion started by: Venkatesh1
7 Replies

2. Shell Programming and Scripting

Pipe output missing date?

I'd like to have the output from this script piped to a text file that has the date at the beginning of it. For example, my ideal would be something like this $./run_script.sh $ls *.out 2013-Feb-26-output_filename.out Here's the code I'm using. #! /bin/ksh DAT=`date '+%Y-%b-%d'` for... (2 Replies)
Discussion started by: DustinT
2 Replies

3. Solaris

[solved]Config/enable_mapping missing, how to add?

Issue resolved by upgrading from solaris 11 to solaris 11.1 I would like to enable network mapping. While using instructions from: https://blogs.oracle.com/VDIpier/entry/solaris_11_changing_the_hostname To change my hostname I noticed I am missing the enable mapping bool. What it should... (0 Replies)
Discussion started by: taltamir
0 Replies

4. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

5. Solaris

[solved] Group sysadmin missing

Hello all I recently installed a fresh copy of Solaris. I noticed that /etc/passwd does not contain an entry for sysadmin Group #14. Why isnt it there? Other websites state that by default it should be there ! Help! Regards, Junaid ---------- Post updated at 01:04 AM ----------... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

6. Red Hat

[Solved: Missing A Record] DNS issue

Hi, I have recently built a new DNS server and created a new zone. I use an ESMTP server to handle mail and the new domain has been added to this. I can send mail to gmail and other domain addresses but unable to send it to one particular domain. (DSN:Service Unavailable) DNS... (2 Replies)
Discussion started by: Duffs22
2 Replies

7. Shell Programming and Scripting

Missing date

hi team, i have a file contains data as follows F1 file --------------------------- date system name 1-jan-2012 x 1-jan-2012 y 1-jan-2012 x 5-jan-2012 y 3-jan-2012 z 3-jan-2012 z 4-jan-2012 x 4-jan-2012 x ... (13 Replies)
Discussion started by: rabindratech
13 Replies

8. Shell Programming and Scripting

[Solved] line breaks missing when emailed from unix to win

hi i am sending an email from unix to windows platform and using uuencode to attach the plain text files (.txt). But when i read the attached file in notepad the linebreaks are gone. uuencode samplefile.txt samplefile.txt | mail -s "test email" <mailid.com> if i copy paste the... (6 Replies)
Discussion started by: midhun19
6 Replies

9. UNIX for Advanced & Expert Users

Solved: Missing whatis file from my /usr/shar/lib directory...

My whatis file is missing from my /usr/share/lib directory. I know I can recreate it by using catman -w command. My question is, why do all of my other servers have it and this one doesn't. Maybe due to a recent move of old to new servers and it just wasn't copied over. Unlikely, 'cause all... (0 Replies)
Discussion started by: zixzix01
0 Replies

10. UNIX for Dummies Questions & Answers

[SOLVED] mysql.sock is missing..

mysql.sock file is missing in /opt/lampp/etc/ is there any backup file available in unix... since without that file .. project is not opening.. reply me as soon as possible ... (19 Replies)
Discussion started by: senkerth
19 Replies
Login or Register to Ask a Question