Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query data range

Status
Not open for further replies.

mrcuser

Technical User
Aug 26, 2008
22
GB
Is it possible in awk to search on a particular field (say the 6th) to identify a gap in date that aren't in the file if you know the date ranges?
i.e
The file contains:

blah blah blah blah blah 06/03/2008
blah blah blah blah blah 07/03/2008
blah blah blah blah blah 09/03/2008

So i'd want to pick out the fact that the 08/03/2008 wasn't in the file ?
I really have no idea where to start on this as i'm picking awk backup from around 6 years ago!
 
Hi

This is [tt]gawk[/tt] only. Sorry, I have no time now to write a POSIX compliant one.
Code:
awk '{n=d($6);if(NR>1)for(i=l+60*60*24;i<n;i+=60*60*24)print "missing",strftime("%d/%m/%Y",i);l=n}1;function d(w){match(w,"([[:digit:]]+)/([[:digit:]]+)/([[:digit:]]+)",a);return mktime(a[3]" "a[2]" "a[1]" 00 00 00")}' /input/file


Feherke.
 
Try this more POSIXy (but less beautiful) solution:

Code:
awk -F '[ /]' '
        NR>1 && ! ( \
                $6 == prevdate+1 || ( \
                        $7 == prevmonth+1 && \
                        prevdate == prevmonthlastdate \
                ) || ( \
                        $8 == prevyear+1 \
                        && prevmonth == 12 \
                        && prevdate == prevmonthlastdate \
                ) \
        ) {
                print "the following dates are not sequential:"
                print prevline
                print
        }
        $7 != prevmonth {
                cmd="echo $(cal " $7 " " $8 " | tail +3)"
                cmd | getline cal
                close(cmd)
                n=split(cal,a)
                prevmonthlastdate=a[n]
        }
        {
                prevdate=$6
                prevmonth=$7
                prevyear=$8
                prevline=$0
        }
' inputfile

Annihilannic.
 
Well beauty is in the eye of the beholder and if this works does it matter!

I'll try this soon and let you know, thanks loads it's really appreciated.

 
Hi

Here is a POSIX [tt]awk[/tt] compliant one, without external dependencies.
Code:
awk 'BEGIN{split("31 28 31 30 31 30 31 31 30 31 30 31",c)}NR>1{while(f!=$6){print"missing",f;f=n(f)}}{f=n($6)};1;function n(w){d=substr(w,1,2)+0;m=substr(w,4,2)+0;y=substr(w,7,4);if(d<c[m]+(m==2&&((y%4==0 && y%100!=0)||y%400==0)))d++;else{d=1;if(m<12)m++;else{m=1;y++}};return sprintf("%02d/%02d/%d",d,m,y)}' /input/file

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top