The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 07-02-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
use `date +%a' '%b' '%d` once is enough. don't put it together with grep. you don't want to call date everytime sed pass a line to grep.

Code:
datepattern=`date +%a' '%b' '%d` 
sed .... | grep $datepattern

with GNU awk

Code:
awk 'BEGIN{
 datepattern = "^"strftime("%a %b %d",systime())
}
/category/{
    if (x ~ datepattern){
        scrape(x)        
    }
    getline l
    if (l ~ datepattern){
        # do something with below line
    }   
}
{
 x=$0
}
function scrape(s){
        o=s
        gsub(/.*<location>/,"",o)       
        gsub(/<\/location>.*/,"",o)
        print "location: ",o
        gsub(/.*<department>/,"",x)
        gsub(/<\/department>.*/,"",x) 
        print "dept: "x
}' file