Missing date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Missing date
# 1  
Old 09-10-2012
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

now i want missing system date if any from F2.

for example: let say x system date is not available in this file for 2,3 jan2012. if not available then i need to display 0 for missing date for system x.

let say z system date is not available in this file for 1,2 jan2012. if not available then i need to display 0 for missing date for system y.


Please let me know if you have any queries.




quick reply must be appreciated.
# 2  
Old 09-10-2012
What would the output look like given your the F1 file above?
# 3  
Old 09-10-2012
Quote:
Originally Posted by Chubler_XL
What would the output look like given your the F1 file above?

the output will be like as below.
date systemName count
1-jan-2012 x 1
1-jan-2012 x 0
2-jan-2012 x 0
3-jan-2012 x 0
1-jan-2012 y 0
2-jan-2012 y 0
3-jan-2012 y 0
4-jan-2012 y 1
1-jan-2012 z 0
2-jan-2012 z 0
3-jan-2012 z 0

# 4  
Old 09-10-2012
Why no 4-jan-2012 z 0 record ?
# 5  
Old 09-10-2012
o/p :
4-jan-2012 y 2
---as it is 2 time available in file
# 6  
Old 09-10-2012
If you have gnu awk you could do this:

Code:
awk -F "[- ]" '
BEGIN {
   split("jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec", mth, ",")
   for(i=1;i<=12;i++) m[mth[i]]=i;
   min=999999999999;
   OFS=" "
   print "date", "systemName","count"
}
NR>1{
  dt=mktime(sprintf("%04d %02d %02d 00 00 00", $3, m[$2], $1));
  min=min>dt?dt:min;
  max=max<dt?dt:max;
  h[$4]
  c[dt,$4]++
}
END {
   for(host in h)
      for(d=min;d<=max;d+=3600*24)
          print strftime("%d-%b-%Y", d),host, (d SUBSEP host) in c ? c[d,host] : 0
}' infile

# 7  
Old 09-10-2012
file content sample
--------------------------
Code:
01-aug-12,-
01-aug-12,-
01-aug-12,ARTACT001
01-aug-12,ARTACT001
01-aug-12,ARTACT001
01-aug-12,ARTACT001
01-aug-12,ARTBRIO
01-aug-12,ARTBRIO
01-aug-12,ARTBRIO
01-aug-12,ARTBRIO

your output is below:
Code:
01-Aug-12 i1b 3
02-Aug-12 i1b 3
03-Aug-12 i1b 3
04-Aug-12 i1b 3
05-Aug-12 i1b 2
06-Aug-12 i1b 2
07-Aug-12 i1b 2
08-Aug-12 i1b 2
09-Aug-12 i1b 2
10-Aug-12 i1b 2
11-Aug-12 i1b 2

Please let me know if you have any queries.

Last edited by Franklin52; 09-12-2012 at 05:00 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. Shell Programming and Scripting

How to add missing date and time in a bash script?

Hi Again, I have a file that contains date and time for the past 2 hours. What i need is add missing date and time in a file. INPUT 2016-01-13 01:33 10 2016-01-13 01:31 10 2016-01-13 01:30 10 2016-01-13 01:29 10 2016-01-13 01:28 10 2016-01-13 01:27 10 2016-01-13 01:26 10 2016-01-13... (14 Replies)
Discussion started by: ernesto
14 Replies

3. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

4. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

5. 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

6. 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

7. Shell Programming and Scripting

How to find the Missing date inside the FILE?

Hi am using Unix AIX Ksh have a FILE CAT FILE 08/02/2013 16/02/2013 18/02/2013 I need the Outputs as Missing date are 09/02/2013 to 15/02/2013,17/02/2013 can anyone help me !!! (1 Reply)
Discussion started by: Venkatesh1
1 Replies

8. Shell Programming and Scripting

[Solved] missing date in unix

i have a file with below contents 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... (10 Replies)
Discussion started by: rabindratech
10 Replies

9. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

10. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies
Login or Register to Ask a Question