awk - for holidays in a files


 
Thread Tools Search this Thread
Operating Systems HP-UX awk - for holidays in a files
# 1  
Old 05-28-2010
awk - for holidays in a files

Hello:

Kind of new to scripting

I am having a problem parsing out indivdual dates

this works

file 'public.holidays'
Code:
20070101 20070115 20070219 20070528 20070704 20070903
20071008 20071112 20071122 20071225 
20080101 20080121 20080218 20080526 20080704 20080901
20081013 20081111 20081127 20081225 
20090101 20090119 20090216 20090525 20090907 20091012
20091111 20091126 20091225 20100101 20100118 20100215
20100705 20100906 20101011 
20101111 20101125 20101225 
20100531
 
#forcing local_date to test 
#local_date=$year$month$day
local_date=20100531
 
awk -F" " -v local=$local_date ' 
{ 
for (i=1; i <= NF; i++) 
{ print $i; _nf=$i; } 
} 
END { 
if (_nf==local) {print "match " _nf " " local; } 
else {print "no match " _nf " " "end"; } 
}' public.holidays

output to screen
Code:
20101011 
20101111 
20101125 
20101225 
20100531 
match 20100531 20100531

this does not
Code:
20070101 20070115 20070219 20070528 20070704 20070903
20071008 20071112 20071122 20071225 
20080101 20080121 20080218 20080526 20080704 20080901
20081013 20081111 20081127 20081225 
20090101 20090119 20090216 20090525 20090907 20091012
20091111 20091126 20091225 20100101 20100118 20100215
20100531 20100705 20100906 20101011 
20101111 20101125 20101225

output to screen
Code:
20101111 
20101125 
20101225 
no match 20101225 end

Any ideas ?
Thank you.

Last edited by Scott; 05-28-2010 at 07:05 PM.. Reason: Please use code tags
Bill L.
# 2  
Old 05-29-2010
Do you want to print all of that or just "match seachdate founddate" or "no match searchdate"

Code:
awk -v dt=$local_date ' index($0,dt)>0 {print "match ", dt, dt; exit}
                                END{print "no match", dt}'  public_holidays

# 3  
Old 05-29-2010
just match/nomatch - this is great
added after
END
{ if (_nf ne "match") {print "no match", dt} }
character not equal in AWK if is? ne, ^= - I'll look around
Bill L.
# 4  
Old 05-29-2010
!= is 'not equal' in awk
# 5  
Old 05-29-2010
thanks - this is much betteer than what I had -
Bill L.
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. News, Links, Events and Announcements

Happy Holidays and New Year!

To All UNIX Forum Members! Neo has sent you a flash greeting card. You may see it by clicking on the link below: http://www.afreegreetingcard.com/cgi-bin/magiccard.cgi?122920242420332 :) (5 Replies)
Discussion started by: Neo
5 Replies
Login or Register to Ask a Question