Missing date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Missing date
# 8  
Old 09-10-2012
Umm, you've changed the format of the input file.

Updated solution for:
  • 2-digit year
  • comma as FS
  • no header row
  • "-" as hostname

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"
}
{
  if(length($4)==0) $4="-"
  if($3 < 1800) $3+=2000
  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 tolower(strftime("%d-%b-%Y", d)),host, (d SUBSEP host) in c ? c[d,host] : 0
}' infile

# 9  
Old 09-10-2012
really its a smart answer..you are in track

input file format is like this
-------------------------------------
Code:
01-aug-12,-,cpu
03-aug-12,-,mem
01-aug-12,ARTACT001
01-aug-12,ARTACT001
01-aug-12,ARTACT001
01-aug-12,ARTACT001
01-aug-12,ARTBRIO,cpu
03-aug-12,ARTBRIO,disk

The output will be like this..
-----------------------------
Code:
01-aug-12,-,cpu,1
02-aug-12,-,cpu,0
03-aug-12,-,cpu,1
01-aug-12,ARTACT001,3
01-aug-12,ARTBRIO,cpu,1
02-aug-12,ARTBRIO,0
03-aug-12,ARTBRIO,disk

quick response will really appriciated.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 09-10-2012 at 03:26 PM.. Reason: code tags, please!
# 10  
Old 09-12-2012
MySQL

Hi friend,


can you please advice for the below scenario :

if any of component i.e. cpu/mem/disk missing , then i need to know missing date with component name.


Thanks
Rabindra
# 11  
Old 09-12-2012
Try this:

Code:
awk '
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=","
}
/,/ {
  p=index($0,",")
  split(substr($0,1,p),f,"-")
  dt=mktime(sprintf("%04d %02d %02d 00 00 00", 2000+f[3], m[f[2]], f[1]));
  min=min>dt?dt:min;
  max=max<dt?dt:max;
  h[substr($0,p+1)]
  c[dt,substr($0,p+1)]++
}
END {
   for(host in h)
      for(d=min;d<=max;d+=3600*24)
          print tolower(strftime("%d-%b-%y", d)),host, (d SUBSEP host) in c ? c[d,host] : 0
}' infile

# 12  
Old 09-30-2012
MySQL

hi friend,

previous code is working fine. Now this is my file contents
Code:
-----------------------------------
component,available_date,count
-----------------------------------
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

then my output would be
----------------------------
Code:
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

need your help asap.

Last edited by vbe; 10-02-2012 at 10:47 AM..
# 13  
Old 10-02-2012
still i am on doubt. need your help soon. please let me know you have any queries.
# 14  
Old 10-02-2012
This is solved in https://www.unix.com/shell-programmin...#post302708793. I'm not sure double posting really helps.
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