[Solved] missing date in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] missing date in unix
# 1  
Old 09-28-2012
[Solved] missing date in unix

i have a file with below contents
Code:
Mg_Message_count,1-Aug-12,46
Mg_Message_count,2-Aug-12,48
Mg_Message_count,3-Aug-12,48
Mg_Message_count,4-Aug-12,48
Mg_Message_count,5-Aug-12,48
Mg_Message_count,6-Aug-12,48
Mg_Message_count,7-Aug-12,42
Mg_Message_count,20-Aug-12,24
Mg_Message_count,21-Aug-12,24
Mg_Message_count,22-Aug-12,24
Mg_Message_count,23-Aug-12,24
Mg_Message_count,24-Aug-12,24
Mg_Message_count,25-Aug-12,24

i want to know missing date 8-sept-12 to 19-sept-12 need display 0
otherwise display specific count
o/p
-------------------------------------
Code:
Mg_Message_count,1-Aug-12,46
Mg_Message_count,2-Aug-12,48
Mg_Message_count,3-Aug-12,48
Mg_Message_count,4-Aug-12,48
Mg_Message_count,5-Aug-12,48
Mg_Message_count,6-Aug-12,48
Mg_Message_count,7-Aug-12,42
Mg_Message_count,8-Aug-12,0
Mg_Message_count,9-Aug-12,0
Mg_Message_count,10-Aug-12,0
Mg_Message_count,11-Aug-12,0
Mg_Message_count,12-Aug-12,0
Mg_Message_count,13-Aug-12,0
Mg_Message_count,14-Aug-12,0
Mg_Message_count,15-Aug-12,0
Mg_Message_count,16-Aug-12,0
Mg_Message_count,17-Aug-12,0
Mg_Message_count,18-Aug-12,0
Mg_Message_count,19-Aug-12,0
Mg_Message_count,20-Aug-12,24
Mg_Message_count,21-Aug-12,24
Mg_Message_count,22-Aug-12,24
Mg_Message_count,23-Aug-12,24
Mg_Message_count,24-Aug-12,24
Mg_Message_count,25-Aug-12,24

quickly reply must be appriciated

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by vbe; 09-28-2012 at 08:56 AM..
# 2  
Old 09-28-2012
try this...

Code:
awk -F "[-,]" '{if(a){if(($2-a) > 1){p=$1",";q="-"$3"-"$4",0";a++;for(i=a;i<=$2;i++){a++;print p""i""q;}}else{a=$2;print $0}}else{a=$2;print $0}}' file

# 3  
Old 09-30-2012
not giving correct output for example
Mg_Message_count,8-Aug-12,0 Mg_Message_count,9-Aug-12,0 Mg_Message_count,10-Aug-12,0 Mg_Message_count,11-Aug-12,0 Mg_Message_count,12-Aug-12,0 Mg_Message_count,13-Aug-12,0 Mg_Message_count,14-Aug-12,0 Mg_Message_count,15-Aug-12,0 Mg_Message_count,16-Aug-12,0 Mg_Message_count,17-Aug-12,0 Mg_Message_count,18-Aug-12,0 Mg_Message_count,19-Aug-12,0

those are not available in my file hence for those date will be 0
---------------
Logic
if date available then display
(for example:Mg_Message_count,07-Aug-12,42)
else display count 0
for example:Mg_Message_count,11-Aug-12,0

---------- Post updated at 12:39 AM ---------- Previous update was at 12:27 AM ----------

Please let me you have any doubt

Last edited by rabindratech; 09-30-2012 at 02:37 AM.. Reason: to clarify
# 4  
Old 09-30-2012
Quote:
Originally Posted by rabindratech
those are not available in my file hence for those date will be 0
---------------
Logic
if date available then display - original...right..?
(for example:Mg_Message_count,07-Aug-12,42)
else display count 0
for example:Mg_Message_count,11-Aug-12,0

---------- Post updated at 12:39 AM ---------- Previous update was at 12:27 AM ----------

Please let me you have any doubt
see this..
Code:
$ cat file
Mg_Message_count,1-Aug-12,46
Mg_Message_count,2-Aug-12,48
Mg_Message_count,3-Aug-12,48
Mg_Message_count,4-Aug-12,48
Mg_Message_count,5-Aug-12,48
Mg_Message_count,6-Aug-12,48
Mg_Message_count,7-Aug-12,42
Mg_Message_count,20-Aug-12,24
Mg_Message_count,21-Aug-12,24
Mg_Message_count,22-Aug-12,24
Mg_Message_count,23-Aug-12,24
Mg_Message_count,24-Aug-12,24
Mg_Message_count,25-Aug-12,24

$ awk -F "[-,]" '{if(a){if(($2-a) > 1){p=$1",";q="-"$3"-"$4",0";a++;for(i=a;i<$2;i++){a++;print p""i""q;}{print}}else{a=$2;print $0}}else{a=$2;print $0}}' file
Mg_Message_count,1-Aug-12,46
Mg_Message_count,2-Aug-12,48
Mg_Message_count,3-Aug-12,48
Mg_Message_count,4-Aug-12,48
Mg_Message_count,5-Aug-12,48
Mg_Message_count,6-Aug-12,48
Mg_Message_count,7-Aug-12,42
Mg_Message_count,8-Aug-12,0
Mg_Message_count,9-Aug-12,0
Mg_Message_count,10-Aug-12,0
Mg_Message_count,11-Aug-12,0
Mg_Message_count,12-Aug-12,0
Mg_Message_count,13-Aug-12,0
Mg_Message_count,14-Aug-12,0
Mg_Message_count,15-Aug-12,0
Mg_Message_count,16-Aug-12,0
Mg_Message_count,17-Aug-12,0
Mg_Message_count,18-Aug-12,0
Mg_Message_count,19-Aug-12,0
Mg_Message_count,20-Aug-12,24
Mg_Message_count,21-Aug-12,24
Mg_Message_count,22-Aug-12,24
Mg_Message_count,23-Aug-12,24
Mg_Message_count,24-Aug-12,24
Mg_Message_count,25-Aug-12,24

small correction in the code.. check above...

let me know if you still have any more conditions..? or you need another output..?
# 5  
Old 09-30-2012
Some questions around your problem: Does it span months? Does it need to cover month's end? If not, and being exactly as given in your post, try (using mawk on linux):
Code:
awk 'BEGIN{FS=OFS=","}
     {split($2,B,"-");
      while (B[1]!=++A) {h=sprintf ("%s-%s-%s", A,B[2],B[3]); print $1,h,"0"}
      A=B[1]
      print
     }
    ' file

# 6  
Old 10-01-2012
this is giving the below output like
------------------
Code:
,235--,0
,236--,0
,237--,0
,238--,0
,239--,0

explanation:this is my input file as below given example. now thae date between 08-AUG-12 to 19-AUG-12 are missing/not available hence i need the count (Last field ) is 0 for dtd 08-AUG-12 to 19-AUG-12 else as it is.

Example:
Code:
MNP_Message_Gateway,Mg_Message_count,07-AUG-12,42
MNP_Message_Gateway,Mg_Message_count,20-AUG-12,24


Last edited by vbe; 10-02-2012 at 10:41 AM.. Reason: code tags : Last warning!
# 7  
Old 10-01-2012
Quote:
Originally Posted by rabindratech
Example:
MNP_Message_Gateway,Mg_Message_count,07-AUG-12,42
MNP_Message_Gateway,Mg_Message_count,20-AUG-12,24
Please look at your input file it is different than what you have given in the first post..

try this...
Code:
$ cat file
MNP_Message_Gateway,Mg_Message_count,07-AUG-12,42
MNP_Message_Gateway,Mg_Message_count,20-AUG-12,24

$ 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
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


Last edited by pamu; 10-01-2012 at 02:41 AM..
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